01: package org.bouncycastle.asn1.ocsp;
02:
03: import org.bouncycastle.asn1.ASN1EncodableVector;
04: import org.bouncycastle.asn1.ASN1Sequence;
05: import org.bouncycastle.asn1.ASN1TaggedObject;
06: import org.bouncycastle.asn1.ASN1Encodable;
07: import org.bouncycastle.asn1.DERBitString;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.DERTaggedObject;
11: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
12:
13: public class BasicOCSPResponse extends ASN1Encodable {
14: private ResponseData tbsResponseData;
15: private AlgorithmIdentifier signatureAlgorithm;
16: private DERBitString signature;
17: private ASN1Sequence certs;
18:
19: public BasicOCSPResponse(ResponseData tbsResponseData,
20: AlgorithmIdentifier signatureAlgorithm,
21: DERBitString signature, ASN1Sequence certs) {
22: this .tbsResponseData = tbsResponseData;
23: this .signatureAlgorithm = signatureAlgorithm;
24: this .signature = signature;
25: this .certs = certs;
26: }
27:
28: public BasicOCSPResponse(ASN1Sequence seq) {
29: this .tbsResponseData = ResponseData.getInstance(seq
30: .getObjectAt(0));
31: this .signatureAlgorithm = AlgorithmIdentifier.getInstance(seq
32: .getObjectAt(1));
33: this .signature = (DERBitString) seq.getObjectAt(2);
34:
35: if (seq.size() > 3) {
36: this .certs = ASN1Sequence.getInstance(
37: (ASN1TaggedObject) seq.getObjectAt(3), true);
38: }
39: }
40:
41: public static BasicOCSPResponse getInstance(ASN1TaggedObject obj,
42: boolean explicit) {
43: return getInstance(ASN1Sequence.getInstance(obj, explicit));
44: }
45:
46: public static BasicOCSPResponse getInstance(Object obj) {
47: if (obj == null || obj instanceof BasicOCSPResponse) {
48: return (BasicOCSPResponse) obj;
49: } else if (obj instanceof ASN1Sequence) {
50: return new BasicOCSPResponse((ASN1Sequence) obj);
51: }
52:
53: throw new IllegalArgumentException("unknown object in factory");
54: }
55:
56: public ResponseData getTbsResponseData() {
57: return tbsResponseData;
58: }
59:
60: public AlgorithmIdentifier getSignatureAlgorithm() {
61: return signatureAlgorithm;
62: }
63:
64: public DERBitString getSignature() {
65: return signature;
66: }
67:
68: public ASN1Sequence getCerts() {
69: return certs;
70: }
71:
72: /**
73: * Produce an object suitable for an ASN1OutputStream.
74: * <pre>
75: * BasicOCSPResponse ::= SEQUENCE {
76: * tbsResponseData ResponseData,
77: * signatureAlgorithm AlgorithmIdentifier,
78: * signature BIT STRING,
79: * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
80: * </pre>
81: */
82: public DERObject toASN1Object() {
83: ASN1EncodableVector v = new ASN1EncodableVector();
84:
85: v.add(tbsResponseData);
86: v.add(signatureAlgorithm);
87: v.add(signature);
88: if (certs != null) {
89: v.add(new DERTaggedObject(true, 0, certs));
90: }
91:
92: return new DERSequence(v);
93: }
94: }
|