001: package org.bouncycastle.asn1.ocsp;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DERGeneralizedTime;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERSequence;
010: import org.bouncycastle.asn1.DERTaggedObject;
011: import org.bouncycastle.asn1.x509.X509Extensions;
012:
013: public class SingleResponse extends ASN1Encodable {
014: private CertID certID;
015: private CertStatus certStatus;
016: private DERGeneralizedTime this Update;
017: private DERGeneralizedTime nextUpdate;
018: private X509Extensions singleExtensions;
019:
020: public SingleResponse(CertID certID, CertStatus certStatus,
021: DERGeneralizedTime this Update,
022: DERGeneralizedTime nextUpdate,
023: X509Extensions singleExtensions) {
024: this .certID = certID;
025: this .certStatus = certStatus;
026: this .this Update = this Update;
027: this .nextUpdate = nextUpdate;
028: this .singleExtensions = singleExtensions;
029: }
030:
031: public SingleResponse(ASN1Sequence seq) {
032: this .certID = CertID.getInstance(seq.getObjectAt(0));
033: this .certStatus = CertStatus.getInstance(seq.getObjectAt(1));
034: this .this Update = (DERGeneralizedTime) seq.getObjectAt(2);
035:
036: if (seq.size() > 4) {
037: this .nextUpdate = DERGeneralizedTime.getInstance(
038: (ASN1TaggedObject) seq.getObjectAt(3), true);
039: this .singleExtensions = X509Extensions.getInstance(
040: (ASN1TaggedObject) seq.getObjectAt(4), true);
041: } else if (seq.size() > 3) {
042: ASN1TaggedObject o = (ASN1TaggedObject) seq.getObjectAt(3);
043:
044: if (o.getTagNo() == 0) {
045: this .nextUpdate = DERGeneralizedTime.getInstance(o,
046: true);
047: } else {
048: this .singleExtensions = X509Extensions.getInstance(o,
049: true);
050: }
051: }
052: }
053:
054: public static SingleResponse getInstance(ASN1TaggedObject obj,
055: boolean explicit) {
056: return getInstance(ASN1Sequence.getInstance(obj, explicit));
057: }
058:
059: public static SingleResponse getInstance(Object obj) {
060: if (obj == null || obj instanceof SingleResponse) {
061: return (SingleResponse) obj;
062: } else if (obj instanceof ASN1Sequence) {
063: return new SingleResponse((ASN1Sequence) obj);
064: }
065:
066: throw new IllegalArgumentException("unknown object in factory");
067: }
068:
069: public CertID getCertID() {
070: return certID;
071: }
072:
073: public CertStatus getCertStatus() {
074: return certStatus;
075: }
076:
077: public DERGeneralizedTime getThisUpdate() {
078: return this Update;
079: }
080:
081: public DERGeneralizedTime getNextUpdate() {
082: return nextUpdate;
083: }
084:
085: public X509Extensions getSingleExtensions() {
086: return singleExtensions;
087: }
088:
089: /**
090: * Produce an object suitable for an ASN1OutputStream.
091: * <pre>
092: * SingleResponse ::= SEQUENCE {
093: * certID CertID,
094: * certStatus CertStatus,
095: * thisUpdate GeneralizedTime,
096: * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
097: * singleExtensions [1] EXPLICIT Extensions OPTIONAL }
098: * </pre>
099: */
100: public DERObject toASN1Object() {
101: ASN1EncodableVector v = new ASN1EncodableVector();
102:
103: v.add(certID);
104: v.add(certStatus);
105: v.add(this Update);
106:
107: if (nextUpdate != null) {
108: v.add(new DERTaggedObject(true, 0, nextUpdate));
109: }
110:
111: if (singleExtensions != null) {
112: v.add(new DERTaggedObject(true, 1, singleExtensions));
113: }
114:
115: return new DERSequence(v);
116: }
117: }
|