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.DERGeneralizedTime;
008: import org.bouncycastle.asn1.DERInteger;
009: import org.bouncycastle.asn1.DERObject;
010: import org.bouncycastle.asn1.DERSequence;
011: import org.bouncycastle.asn1.DERTaggedObject;
012: import org.bouncycastle.asn1.x509.X509Extensions;
013:
014: public class ResponseData extends ASN1Encodable {
015: private static final DERInteger V1 = new DERInteger(0);
016:
017: private boolean versionPresent;
018:
019: private DERInteger version;
020: private ResponderID responderID;
021: private DERGeneralizedTime producedAt;
022: private ASN1Sequence responses;
023: private X509Extensions responseExtensions;
024:
025: public ResponseData(DERInteger version, ResponderID responderID,
026: DERGeneralizedTime producedAt, ASN1Sequence responses,
027: X509Extensions responseExtensions) {
028: this .version = version;
029: this .responderID = responderID;
030: this .producedAt = producedAt;
031: this .responses = responses;
032: this .responseExtensions = responseExtensions;
033: }
034:
035: public ResponseData(ResponderID responderID,
036: DERGeneralizedTime producedAt, ASN1Sequence responses,
037: X509Extensions responseExtensions) {
038: this (V1, responderID, producedAt, responses, responseExtensions);
039: }
040:
041: public ResponseData(ASN1Sequence seq) {
042: int index = 0;
043:
044: if (seq.getObjectAt(0) instanceof ASN1TaggedObject) {
045: ASN1TaggedObject o = (ASN1TaggedObject) seq.getObjectAt(0);
046:
047: if (o.getTagNo() == 0) {
048: this .versionPresent = true;
049: this .version = DERInteger.getInstance(
050: (ASN1TaggedObject) seq.getObjectAt(0), true);
051: index++;
052: } else {
053: this .version = V1;
054: }
055: } else {
056: this .version = V1;
057: }
058:
059: this .responderID = ResponderID.getInstance(seq
060: .getObjectAt(index++));
061: this .producedAt = (DERGeneralizedTime) seq.getObjectAt(index++);
062: this .responses = (ASN1Sequence) seq.getObjectAt(index++);
063:
064: if (seq.size() > index) {
065: this .responseExtensions = X509Extensions.getInstance(
066: (ASN1TaggedObject) seq.getObjectAt(index), true);
067: }
068: }
069:
070: public static ResponseData getInstance(ASN1TaggedObject obj,
071: boolean explicit) {
072: return getInstance(ASN1Sequence.getInstance(obj, explicit));
073: }
074:
075: public static ResponseData getInstance(Object obj) {
076: if (obj == null || obj instanceof ResponseData) {
077: return (ResponseData) obj;
078: } else if (obj instanceof ASN1Sequence) {
079: return new ResponseData((ASN1Sequence) obj);
080: }
081:
082: throw new IllegalArgumentException("unknown object in factory");
083: }
084:
085: public DERInteger getVersion() {
086: return version;
087: }
088:
089: public ResponderID getResponderID() {
090: return responderID;
091: }
092:
093: public DERGeneralizedTime getProducedAt() {
094: return producedAt;
095: }
096:
097: public ASN1Sequence getResponses() {
098: return responses;
099: }
100:
101: public X509Extensions getResponseExtensions() {
102: return responseExtensions;
103: }
104:
105: /**
106: * Produce an object suitable for an ASN1OutputStream.
107: * <pre>
108: * ResponseData ::= SEQUENCE {
109: * version [0] EXPLICIT Version DEFAULT v1,
110: * responderID ResponderID,
111: * producedAt GeneralizedTime,
112: * responses SEQUENCE OF SingleResponse,
113: * responseExtensions [1] EXPLICIT Extensions OPTIONAL }
114: * </pre>
115: */
116: public DERObject toASN1Object() {
117: ASN1EncodableVector v = new ASN1EncodableVector();
118:
119: if (versionPresent || !version.equals(V1)) {
120: v.add(new DERTaggedObject(true, 0, version));
121: }
122:
123: v.add(responderID);
124: v.add(producedAt);
125: v.add(responses);
126: if (responseExtensions != null) {
127: v.add(new DERTaggedObject(true, 1, responseExtensions));
128: }
129:
130: return new DERSequence(v);
131: }
132: }
|