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