01: package org.bouncycastle.asn1.cmp;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1OctetString;
06: import org.bouncycastle.asn1.ASN1Sequence;
07: import org.bouncycastle.asn1.DEREncodable;
08: import org.bouncycastle.asn1.DERInteger;
09: import org.bouncycastle.asn1.DERObject;
10: import org.bouncycastle.asn1.DERSequence;
11:
12: public class CertResponse extends ASN1Encodable {
13: private DERInteger certReqId;
14: private PKIStatusInfo status;
15: private CertifiedKeyPair certifiedKeyPair;
16: private ASN1OctetString rspInfo;
17:
18: private CertResponse(ASN1Sequence seq) {
19: certReqId = DERInteger.getInstance(seq.getObjectAt(0));
20: status = PKIStatusInfo.getInstance(seq.getObjectAt(1));
21:
22: if (seq.size() >= 3) {
23: if (seq.size() == 3) {
24: DEREncodable o = seq.getObjectAt(2);
25: if (o instanceof ASN1OctetString) {
26: rspInfo = ASN1OctetString.getInstance(o);
27: } else {
28: certifiedKeyPair = CertifiedKeyPair.getInstance(o);
29: }
30: } else {
31: certifiedKeyPair = CertifiedKeyPair.getInstance(seq
32: .getObjectAt(2));
33: rspInfo = ASN1OctetString.getInstance(seq
34: .getObjectAt(3));
35: }
36: }
37: }
38:
39: public static CertResponse getInstance(Object o) {
40: if (o instanceof CertResponse) {
41: return (CertResponse) o;
42: }
43:
44: if (o instanceof ASN1Sequence) {
45: return new CertResponse((ASN1Sequence) o);
46: }
47:
48: throw new IllegalArgumentException("Invalid object: "
49: + o.getClass().getName());
50: }
51:
52: public DERInteger getCertReqId() {
53: return certReqId;
54: }
55:
56: public PKIStatusInfo getStatus() {
57: return status;
58: }
59:
60: public CertifiedKeyPair getCertifiedKeyPair() {
61: return certifiedKeyPair;
62: }
63:
64: /**
65: * <pre>
66: * CertResponse ::= SEQUENCE {
67: * certReqId INTEGER,
68: * -- to match this response with corresponding request (a value
69: * -- of -1 is to be used if certReqId is not specified in the
70: * -- corresponding request)
71: * status PKIStatusInfo,
72: * certifiedKeyPair CertifiedKeyPair OPTIONAL,
73: * rspInfo OCTET STRING OPTIONAL
74: * -- analogous to the id-regInfo-utf8Pairs string defined
75: * -- for regInfo in CertReqMsg [CRMF]
76: * }
77: * </pre>
78: * @return a basic ASN.1 object representation.
79: */
80: public DERObject toASN1Object() {
81: ASN1EncodableVector v = new ASN1EncodableVector();
82:
83: v.add(certReqId);
84: v.add(status);
85:
86: if (certifiedKeyPair != null) {
87: v.add(certifiedKeyPair);
88: }
89:
90: if (rspInfo != null) {
91: v.add(rspInfo);
92: }
93:
94: return new DERSequence(v);
95: }
96: }
|