01: package org.bouncycastle.asn1.x509;
02:
03: import org.bouncycastle.asn1.ASN1Choice;
04: import org.bouncycastle.asn1.ASN1Encodable;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1TaggedObject;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERTaggedObject;
09:
10: public class AttCertIssuer extends ASN1Encodable implements ASN1Choice {
11: ASN1Encodable obj;
12: DERObject choiceObj;
13:
14: public static AttCertIssuer getInstance(Object obj) {
15: if (obj instanceof AttCertIssuer) {
16: return (AttCertIssuer) obj;
17: } else if (obj instanceof V2Form) {
18: return new AttCertIssuer(V2Form.getInstance(obj));
19: } else if (obj instanceof GeneralNames) {
20: return new AttCertIssuer((GeneralNames) obj);
21: } else if (obj instanceof ASN1TaggedObject) {
22: return new AttCertIssuer(V2Form.getInstance(
23: (ASN1TaggedObject) obj, false));
24: } else if (obj instanceof ASN1Sequence) {
25: return new AttCertIssuer(GeneralNames.getInstance(obj));
26: }
27:
28: throw new IllegalArgumentException(
29: "unknown object in factory: " + obj.getClass());
30: }
31:
32: public static AttCertIssuer getInstance(ASN1TaggedObject obj,
33: boolean explicit) {
34: return getInstance(obj.getObject()); // must be explictly tagged
35: }
36:
37: /**
38: * Don't use this one if you are trying to be RFC 3281 compliant.
39: * Use it for v1 attribute certificates only.
40: *
41: * @param names our GeneralNames structure
42: */
43: public AttCertIssuer(GeneralNames names) {
44: obj = names;
45: choiceObj = obj.getDERObject();
46: }
47:
48: public AttCertIssuer(V2Form v2Form) {
49: obj = v2Form;
50: choiceObj = new DERTaggedObject(false, 0, obj);
51: }
52:
53: public ASN1Encodable getIssuer() {
54: return obj;
55: }
56:
57: /**
58: * Produce an object suitable for an ASN1OutputStream.
59: * <pre>
60: * AttCertIssuer ::= CHOICE {
61: * v1Form GeneralNames, -- MUST NOT be used in this
62: * -- profile
63: * v2Form [0] V2Form -- v2 only
64: * }
65: * </pre>
66: */
67: public DERObject toASN1Object() {
68: return choiceObj;
69: }
70: }
|