01: package org.bouncycastle.asn1.cmp;
02:
03: import org.bouncycastle.asn1.ASN1Choice;
04: import org.bouncycastle.asn1.ASN1Encodable;
05: import org.bouncycastle.asn1.ASN1TaggedObject;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERTaggedObject;
08: import org.bouncycastle.asn1.crmf.EncryptedValue;
09:
10: public class CertOrEncCert extends ASN1Encodable implements ASN1Choice {
11: private CMPCertificate certificate;
12: private EncryptedValue encryptedCert;
13:
14: private CertOrEncCert(ASN1TaggedObject tagged) {
15: if (tagged.getTagNo() == 0) {
16: certificate = CMPCertificate
17: .getInstance(tagged.getObject());
18: } else if (tagged.getTagNo() == 1) {
19: encryptedCert = EncryptedValue.getInstance(tagged
20: .getObject());
21: } else {
22: throw new IllegalArgumentException("unknown tag: "
23: + tagged.getTagNo());
24: }
25: }
26:
27: public static CertOrEncCert getInstance(Object o) {
28: if (o instanceof CertOrEncCert) {
29: return (CertOrEncCert) o;
30: }
31:
32: if (o instanceof ASN1TaggedObject) {
33: return new CertOrEncCert((ASN1TaggedObject) o);
34: }
35:
36: throw new IllegalArgumentException("Invalid object: "
37: + o.getClass().getName());
38: }
39:
40: public CMPCertificate getCertificate() {
41: return certificate;
42: }
43:
44: public EncryptedValue getEncryptedCert() {
45: return encryptedCert;
46: }
47:
48: /**
49: * <pre>
50: * CertOrEncCert ::= CHOICE {
51: * certificate [0] CMPCertificate,
52: * encryptedCert [1] EncryptedValue
53: * }
54: * </pre>
55: * @return a basic ASN.1 object representation.
56: */
57: public DERObject toASN1Object() {
58: if (certificate != null) {
59: return new DERTaggedObject(true, 0, certificate);
60: }
61:
62: return new DERTaggedObject(true, 1, encryptedCert);
63: }
64: }
|