01: package org.bouncycastle.asn1.ocsp;
02:
03: import org.bouncycastle.asn1.ASN1Choice;
04: import org.bouncycastle.asn1.ASN1OctetString;
05: import org.bouncycastle.asn1.ASN1TaggedObject;
06: import org.bouncycastle.asn1.ASN1Encodable;
07: import org.bouncycastle.asn1.DEREncodable;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DEROctetString;
10: import org.bouncycastle.asn1.DERTaggedObject;
11: import org.bouncycastle.asn1.x509.X509Name;
12:
13: public class ResponderID extends ASN1Encodable implements ASN1Choice {
14: private DEREncodable value;
15:
16: public ResponderID(ASN1OctetString value) {
17: this .value = value;
18: }
19:
20: public ResponderID(X509Name value) {
21: this .value = value;
22: }
23:
24: public static ResponderID getInstance(Object obj) {
25: if (obj == null || obj instanceof ResponderID) {
26: return (ResponderID) obj;
27: } else if (obj instanceof DEROctetString) {
28: return new ResponderID((DEROctetString) obj);
29: } else if (obj instanceof ASN1TaggedObject) {
30: ASN1TaggedObject o = (ASN1TaggedObject) obj;
31:
32: if (o.getTagNo() == 1) {
33: return new ResponderID(X509Name.getInstance(o, true));
34: } else {
35: return new ResponderID(ASN1OctetString.getInstance(o,
36: true));
37: }
38: }
39:
40: return new ResponderID(X509Name.getInstance(obj));
41: }
42:
43: public static ResponderID getInstance(ASN1TaggedObject obj,
44: boolean explicit) {
45: return getInstance(obj.getObject()); // must be explicitly tagged
46: }
47:
48: /**
49: * Produce an object suitable for an ASN1OutputStream.
50: * <pre>
51: * ResponderID ::= CHOICE {
52: * byName [1] Name,
53: * byKey [2] KeyHash }
54: * </pre>
55: */
56: public DERObject toASN1Object() {
57: if (value instanceof ASN1OctetString) {
58: return new DERTaggedObject(true, 2, value);
59: }
60:
61: return new DERTaggedObject(true, 1, value);
62: }
63: }
|