01: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
02: //
03: // Author: Maik Stohn
04: //
05: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
06: // software and associated documentation files (the "Software"), to deal in the Software
07: // without restriction, including without limitation the rights to use, copy, modify, merge,
08: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
09: // to whom the Software is furnished to do so, subject to the following conditions:
10: //
11: // The above copyright notice and this permission notice shall be included in all copies or
12: // substantial portions of the Software.
13: //
14: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15: // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17: // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19:
20: package com.novosec.pkix.asn1.cmp;
21:
22: import org.bouncycastle.asn1.ASN1TaggedObject;
23: import org.bouncycastle.asn1.DEREncodable;
24: import org.bouncycastle.asn1.DERObject;
25: import org.bouncycastle.asn1.DERTaggedObject;
26: import org.bouncycastle.asn1.x509.X509CertificateStructure;
27:
28: import com.novosec.pkix.asn1.crmf.EncryptedValue;
29:
30: /**
31: * ASN.1 structure DER En/DeCoder.
32: *
33: * <pre>
34: * CertOrEncCert ::= CHOICE {
35: * certificate [0] Certificate, (X509CertificateStructure)
36: * encryptedCert [1] EncryptedValue
37: * }
38: *
39: * </pre>
40: */
41: public class CertOrEncCert implements DEREncodable {
42: DEREncodable obj;
43: int tag;
44:
45: public CertOrEncCert(DEREncodable obj, int tag) {
46: this .obj = obj;
47: this .tag = tag;
48: }
49:
50: public X509CertificateStructure getCertificate() {
51: if (this .tag != 0)
52: return null;
53: return (X509CertificateStructure) this .obj;
54: }
55:
56: public EncryptedValue getEncryptedCert() {
57: if (this .tag != 1)
58: return null;
59: return (EncryptedValue) this .obj;
60: }
61:
62: public static CertOrEncCert getInstance(DERObject obj) {
63: return getInstance((ASN1TaggedObject) obj, true);
64: }
65:
66: public static CertOrEncCert getInstance(ASN1TaggedObject tagObj,
67: boolean explicit) {
68: int tag = tagObj.getTagNo();
69:
70: switch (tag) {
71: case 0:
72: return new CertOrEncCert(X509CertificateStructure
73: .getInstance(tagObj.getObject()), 0);
74: case 1:
75: return new CertOrEncCert(EncryptedValue.getInstance(tagObj
76: .getObject()), 1);
77: }
78:
79: throw new IllegalArgumentException("unknown tag: " + tag);
80: }
81:
82: public DERObject getDERObject() {
83: return new DERTaggedObject(true, tag, obj);
84: }
85:
86: public String toString() {
87: return "CertOrEncCert: (" + obj + ")";
88: }
89: }
|