001: package org.bouncycastle.asn1.ocsp;
002:
003: import org.bouncycastle.asn1.ASN1EncodableVector;
004: import org.bouncycastle.asn1.ASN1Sequence;
005: import org.bouncycastle.asn1.ASN1TaggedObject;
006: import org.bouncycastle.asn1.ASN1Encodable;
007: import org.bouncycastle.asn1.DERInteger;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERSequence;
010: import org.bouncycastle.asn1.DERTaggedObject;
011: import org.bouncycastle.asn1.x509.GeneralName;
012: import org.bouncycastle.asn1.x509.X509Extensions;
013:
014: public class TBSRequest extends ASN1Encodable {
015: private static final DERInteger V1 = new DERInteger(0);
016:
017: DERInteger version;
018: GeneralName requestorName;
019: ASN1Sequence requestList;
020: X509Extensions requestExtensions;
021:
022: public TBSRequest(GeneralName requestorName,
023: ASN1Sequence requestList, X509Extensions requestExtensions) {
024: this .version = V1;
025: this .requestorName = requestorName;
026: this .requestList = requestList;
027: this .requestExtensions = requestExtensions;
028: }
029:
030: public TBSRequest(ASN1Sequence seq) {
031: int index = 0;
032:
033: if (seq.getObjectAt(0) instanceof ASN1TaggedObject) {
034: ASN1TaggedObject o = (ASN1TaggedObject) seq.getObjectAt(0);
035:
036: if (o.getTagNo() == 0) {
037: version = DERInteger.getInstance((ASN1TaggedObject) seq
038: .getObjectAt(0), true);
039: index++;
040: } else {
041: version = V1;
042: }
043: } else {
044: version = V1;
045: }
046:
047: if (seq.getObjectAt(index) instanceof ASN1TaggedObject) {
048: requestorName = GeneralName.getInstance(
049: (ASN1TaggedObject) seq.getObjectAt(index++), true);
050: }
051:
052: requestList = (ASN1Sequence) seq.getObjectAt(index++);
053:
054: if (seq.size() == (index + 1)) {
055: requestExtensions = X509Extensions.getInstance(
056: (ASN1TaggedObject) seq.getObjectAt(index), true);
057: }
058: }
059:
060: public static TBSRequest getInstance(ASN1TaggedObject obj,
061: boolean explicit) {
062: return getInstance(ASN1Sequence.getInstance(obj, explicit));
063: }
064:
065: public static TBSRequest getInstance(Object obj) {
066: if (obj == null || obj instanceof TBSRequest) {
067: return (TBSRequest) obj;
068: } else if (obj instanceof ASN1Sequence) {
069: return new TBSRequest((ASN1Sequence) obj);
070: }
071:
072: throw new IllegalArgumentException("unknown object in factory");
073: }
074:
075: public DERInteger getVersion() {
076: return version;
077: }
078:
079: public GeneralName getRequestorName() {
080: return requestorName;
081: }
082:
083: public ASN1Sequence getRequestList() {
084: return requestList;
085: }
086:
087: public X509Extensions getRequestExtensions() {
088: return requestExtensions;
089: }
090:
091: /**
092: * Produce an object suitable for an ASN1OutputStream.
093: * <pre>
094: * TBSRequest ::= SEQUENCE {
095: * version [0] EXPLICIT Version DEFAULT v1,
096: * requestorName [1] EXPLICIT GeneralName OPTIONAL,
097: * requestList SEQUENCE OF Request,
098: * requestExtensions [2] EXPLICIT Extensions OPTIONAL }
099: * </pre>
100: */
101: public DERObject toASN1Object() {
102: ASN1EncodableVector v = new ASN1EncodableVector();
103:
104: //
105: // if default don't include.
106: //
107: if (!version.equals(V1)) {
108: v.add(new DERTaggedObject(true, 0, version));
109: }
110:
111: if (requestorName != null) {
112: v.add(new DERTaggedObject(true, 1, requestorName));
113: }
114:
115: v.add(requestList);
116:
117: if (requestExtensions != null) {
118: v.add(new DERTaggedObject(true, 2, requestExtensions));
119: }
120:
121: return new DERSequence(v);
122: }
123: }
|