01: package org.bouncycastle.asn1.ocsp;
02:
03: import org.bouncycastle.asn1.ASN1Choice;
04: import org.bouncycastle.asn1.ASN1TaggedObject;
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.DEREncodable;
07: import org.bouncycastle.asn1.DERNull;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERTaggedObject;
10:
11: public class CertStatus extends ASN1Encodable implements ASN1Choice {
12: private int tagNo;
13: private DEREncodable value;
14:
15: /**
16: * create a CertStatus object with a tag of zero.
17: */
18: public CertStatus() {
19: tagNo = 0;
20: value = new DERNull();
21: }
22:
23: public CertStatus(RevokedInfo info) {
24: tagNo = 1;
25: value = info;
26: }
27:
28: public CertStatus(int tagNo, DEREncodable value) {
29: this .tagNo = tagNo;
30: this .value = value;
31: }
32:
33: public CertStatus(ASN1TaggedObject choice) {
34: this .tagNo = choice.getTagNo();
35:
36: switch (choice.getTagNo()) {
37: case 0:
38: value = new DERNull();
39: break;
40: case 1:
41: value = RevokedInfo.getInstance(choice, false);
42: break;
43: case 2:
44: value = new DERNull();
45: }
46: }
47:
48: public static CertStatus getInstance(Object obj) {
49: if (obj == null || obj instanceof CertStatus) {
50: return (CertStatus) obj;
51: } else if (obj instanceof ASN1TaggedObject) {
52: return new CertStatus((ASN1TaggedObject) obj);
53: }
54:
55: throw new IllegalArgumentException("unknown object in factory");
56: }
57:
58: public static CertStatus getInstance(ASN1TaggedObject obj,
59: boolean explicit) {
60: return getInstance(obj.getObject()); // must be explicitly tagged
61: }
62:
63: public int getTagNo() {
64: return tagNo;
65: }
66:
67: public DEREncodable getStatus() {
68: return value;
69: }
70:
71: /**
72: * Produce an object suitable for an ASN1OutputStream.
73: * <pre>
74: * CertStatus ::= CHOICE {
75: * good [0] IMPLICIT NULL,
76: * revoked [1] IMPLICIT RevokedInfo,
77: * unknown [2] IMPLICIT UnknownInfo }
78: * </pre>
79: */
80: public DERObject toASN1Object() {
81: return new DERTaggedObject(false, tagNo, value);
82: }
83: }
|