KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > cmp > CertOrEncCert


1 // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
2
//
3
// Author: Maik Stohn
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
// software and associated documentation files (the "Software"), to deal in the Software
7
// without restriction, including without limitation the rights to use, copy, modify, merge,
8
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
// 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 {
43     DEREncodable obj;
44     int tag;
45
46     public CertOrEncCert( DEREncodable obj, int tag )
47     {
48         this.obj = obj;
49         this.tag = tag;
50     }
51
52     public X509CertificateStructure getCertificate()
53     {
54       if( this.tag != 0 )
55         return null;
56       return (X509CertificateStructure)this.obj;
57     }
58
59     public EncryptedValue getEncryptedCert()
60     {
61       if( this.tag != 1 )
62         return null;
63       return (EncryptedValue)this.obj;
64     }
65
66     public static CertOrEncCert getInstance( DERObject obj )
67     {
68       return getInstance( (ASN1TaggedObject)obj, true );
69     }
70
71     public static CertOrEncCert getInstance( ASN1TaggedObject tagObj, boolean explicit )
72     {
73         int tag = tagObj.getTagNo();
74
75         switch (tag)
76         {
77           case 0: return new CertOrEncCert(X509CertificateStructure.getInstance(tagObj.getObject()), 0);
78           case 1: return new CertOrEncCert(EncryptedValue.getInstance(tagObj.getObject()), 1);
79         }
80
81         throw new IllegalArgumentException JavaDoc("unknown tag: " + tag);
82     }
83
84     public DERObject getDERObject()
85     {
86       return new DERTaggedObject(true, tag, obj);
87     }
88
89     public String JavaDoc toString()
90     {
91       return "CertOrEncCert: (" + obj + ")";
92     }
93 }
94
Popular Tags