001: package org.bouncycastle.asn1.cmp;
002:
003: import java.math.BigInteger;
004:
005: import org.bouncycastle.asn1.ASN1Encodable;
006: import org.bouncycastle.asn1.ASN1EncodableVector;
007: import org.bouncycastle.asn1.ASN1Sequence;
008: import org.bouncycastle.asn1.ASN1TaggedObject;
009: import org.bouncycastle.asn1.DERBitString;
010: import org.bouncycastle.asn1.DERInteger;
011: import org.bouncycastle.asn1.DERObject;
012: import org.bouncycastle.asn1.DERSequence;
013:
014: public class PKIStatusInfo extends ASN1Encodable {
015: DERInteger status;
016: PKIFreeText statusString;
017: DERBitString failInfo;
018:
019: public static PKIStatusInfo getInstance(ASN1TaggedObject obj,
020: boolean explicit) {
021: return getInstance(ASN1Sequence.getInstance(obj, explicit));
022: }
023:
024: public static PKIStatusInfo getInstance(Object obj) {
025: if (obj instanceof PKIStatusInfo) {
026: return (PKIStatusInfo) obj;
027: } else if (obj instanceof ASN1Sequence) {
028: return new PKIStatusInfo((ASN1Sequence) obj);
029: }
030:
031: throw new IllegalArgumentException(
032: "unknown object in factory: " + obj.getClass());
033: }
034:
035: public PKIStatusInfo(ASN1Sequence seq) {
036: this .status = DERInteger.getInstance(seq.getObjectAt(0));
037:
038: this .statusString = null;
039: this .failInfo = null;
040:
041: if (seq.size() > 2) {
042: this .statusString = PKIFreeText.getInstance(seq
043: .getObjectAt(1));
044: this .failInfo = DERBitString
045: .getInstance(seq.getObjectAt(2));
046: } else if (seq.size() > 1) {
047: Object obj = seq.getObjectAt(1);
048: if (obj instanceof DERBitString) {
049: this .failInfo = DERBitString.getInstance(obj);
050: } else {
051: this .statusString = PKIFreeText.getInstance(obj);
052: }
053: }
054: }
055:
056: /**
057: * @param status
058: */
059: public PKIStatusInfo(int status) {
060: this .status = new DERInteger(status);
061: }
062:
063: /**
064: * @param status
065: * @param statusString
066: */
067: public PKIStatusInfo(int status, PKIFreeText statusString) {
068: this .status = new DERInteger(status);
069: this .statusString = statusString;
070: }
071:
072: public PKIStatusInfo(int status, PKIFreeText statusString,
073: PKIFailureInfo failInfo) {
074: this .status = new DERInteger(status);
075: this .statusString = statusString;
076: this .failInfo = failInfo;
077: }
078:
079: public BigInteger getStatus() {
080: return status.getValue();
081: }
082:
083: public PKIFreeText getStatusString() {
084: return statusString;
085: }
086:
087: public DERBitString getFailInfo() {
088: return failInfo;
089: }
090:
091: /**
092: * <pre>
093: * PKIStatusInfo ::= SEQUENCE {
094: * status PKIStatus, (INTEGER)
095: * statusString PKIFreeText OPTIONAL,
096: * failInfo PKIFailureInfo OPTIONAL (BIT STRING)
097: * }
098: *
099: * PKIStatus:
100: * granted (0), -- you got exactly what you asked for
101: * grantedWithMods (1), -- you got something like what you asked for
102: * rejection (2), -- you don't get it, more information elsewhere in the message
103: * waiting (3), -- the request body part has not yet been processed, expect to hear more later
104: * revocationWarning (4), -- this message contains a warning that a revocation is imminent
105: * revocationNotification (5), -- notification that a revocation has occurred
106: * keyUpdateWarning (6) -- update already done for the oldCertId specified in CertReqMsg
107: *
108: * PKIFailureInfo:
109: * badAlg (0), -- unrecognized or unsupported Algorithm Identifier
110: * badMessageCheck (1), -- integrity check failed (e.g., signature did not verify)
111: * badRequest (2), -- transaction not permitted or supported
112: * badTime (3), -- messageTime was not sufficiently close to the system time, as defined by local policy
113: * badCertId (4), -- no certificate could be found matching the provided criteria
114: * badDataFormat (5), -- the data submitted has the wrong format
115: * wrongAuthority (6), -- the authority indicated in the request is different from the one creating the response token
116: * incorrectData (7), -- the requester's data is incorrect (for notary services)
117: * missingTimeStamp (8), -- when the timestamp is missing but should be there (by policy)
118: * badPOP (9) -- the proof-of-possession failed
119: *
120: * </pre>
121: */
122: public DERObject toASN1Object() {
123: ASN1EncodableVector v = new ASN1EncodableVector();
124:
125: v.add(status);
126:
127: if (statusString != null) {
128: v.add(statusString);
129: }
130:
131: if (failInfo != null) {
132: v.add(failInfo);
133: }
134:
135: return new DERSequence(v);
136: }
137: }
|