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.DEREnumerated;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.DERTaggedObject;
11:
12: public class OCSPResponse extends ASN1Encodable {
13: OCSPResponseStatus responseStatus;
14: ResponseBytes responseBytes;
15:
16: public OCSPResponse(OCSPResponseStatus responseStatus,
17: ResponseBytes responseBytes) {
18: this .responseStatus = responseStatus;
19: this .responseBytes = responseBytes;
20: }
21:
22: public OCSPResponse(ASN1Sequence seq) {
23: responseStatus = new OCSPResponseStatus(DEREnumerated
24: .getInstance(seq.getObjectAt(0)));
25:
26: if (seq.size() == 2) {
27: responseBytes = ResponseBytes.getInstance(
28: (ASN1TaggedObject) seq.getObjectAt(1), true);
29: }
30: }
31:
32: public static OCSPResponse getInstance(ASN1TaggedObject obj,
33: boolean explicit) {
34: return getInstance(ASN1Sequence.getInstance(obj, explicit));
35: }
36:
37: public static OCSPResponse getInstance(Object obj) {
38: if (obj == null || obj instanceof OCSPResponse) {
39: return (OCSPResponse) obj;
40: } else if (obj instanceof ASN1Sequence) {
41: return new OCSPResponse((ASN1Sequence) obj);
42: }
43:
44: throw new IllegalArgumentException("unknown object in factory");
45: }
46:
47: public OCSPResponseStatus getResponseStatus() {
48: return responseStatus;
49: }
50:
51: public ResponseBytes getResponseBytes() {
52: return responseBytes;
53: }
54:
55: /**
56: * Produce an object suitable for an ASN1OutputStream.
57: * <pre>
58: * OCSPResponse ::= SEQUENCE {
59: * responseStatus OCSPResponseStatus,
60: * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
61: * </pre>
62: */
63: public DERObject toASN1Object() {
64: ASN1EncodableVector v = new ASN1EncodableVector();
65:
66: v.add(responseStatus);
67:
68: if (responseBytes != null) {
69: v.add(new DERTaggedObject(true, 0, responseBytes));
70: }
71:
72: return new DERSequence(v);
73: }
74: }
|