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