01: package org.bouncycastle.asn1.cmp;
02:
03: import org.bouncycastle.asn1.ASN1Choice;
04: import org.bouncycastle.asn1.ASN1Encodable;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.x509.X509CertificateStructure;
08:
09: public class CMPCertificate extends ASN1Encodable implements ASN1Choice {
10: private X509CertificateStructure x509v3PKCert;
11:
12: public CMPCertificate(X509CertificateStructure x509v3PKCert) {
13: if (x509v3PKCert.getVersion() != 2) {
14: throw new IllegalArgumentException(
15: "only version 3 certificates allowed");
16: }
17:
18: this .x509v3PKCert = x509v3PKCert;
19: }
20:
21: public static CMPCertificate getInstance(Object o) {
22: if (o instanceof CMPCertificate) {
23: return (CMPCertificate) o;
24: }
25:
26: if (o instanceof X509CertificateStructure) {
27: return new CMPCertificate((X509CertificateStructure) o);
28: }
29:
30: if (o instanceof ASN1Sequence) {
31: return new CMPCertificate(X509CertificateStructure
32: .getInstance(o));
33: }
34:
35: throw new IllegalArgumentException("Invalid object: "
36: + o.getClass().getName());
37: }
38:
39: public X509CertificateStructure getX509v3PKCert() {
40: return x509v3PKCert;
41: }
42:
43: /**
44: * <pre>
45: * CMPCertificate ::= CHOICE {
46: * x509v3PKCert Certificate
47: * }
48: * </pre>
49: * @return a basic ASN.1 object representation.
50: */
51: public DERObject toASN1Object() {
52: return x509v3PKCert.toASN1Object();
53: }
54: }
|