KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > crmf > PKIArchiveOptions


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.crmf;
21
22 import org.bouncycastle.asn1.ASN1TaggedObject;
23 import org.bouncycastle.asn1.DERBoolean;
24 import org.bouncycastle.asn1.DEREncodable;
25 import org.bouncycastle.asn1.DERObject;
26 import org.bouncycastle.asn1.DEROctetString;
27 import org.bouncycastle.asn1.DERTaggedObject;
28
29 /**
30  * ASN.1 structure DER En/DeCoder.
31  *
32  * <pre>
33  *
34  * PKIArchiveOptions ::= CHOICE {
35  * encryptedPrivKey [0] EncryptedKey, -- the actual value of the private key
36  * keyGenParameters [1] KeyGenParameters, -- parameters which allow the private key to be re-generated (OCTET STRING)
37  * archiveRemGenPrivKey [2] BOOLEAN } -- set to TRUE if sender wishes receiver to archive the private key of a key pair which the receiver generates in response to this request; set to FALSE if no archival is desired.
38  *
39  * </pre>
40  */

41 public class PKIArchiveOptions implements DEREncodable
42 {
43     DEREncodable obj;
44     int tag;
45
46     public PKIArchiveOptions( DEREncodable obj, int tag )
47     {
48         this.obj = obj;
49         this.tag = tag;
50     }
51     
52     public EncryptedKey getEncryptedKey()
53     {
54       if( this.tag != 0 )
55         return null;
56       return (EncryptedKey)this.obj;
57     }
58
59     public DEROctetString getKeyGenParameters()
60     {
61       if( this.tag != 1 )
62         return null;
63       return (DEROctetString)this.obj;
64     }
65
66     public DERBoolean getArchiveRemGenPrivKey()
67     {
68       if( this.tag != 2 )
69         return null;
70       return (DERBoolean)this.obj;
71     }
72
73     public static PKIArchiveOptions getInstance( DERObject obj )
74     {
75       return getInstance( (ASN1TaggedObject)obj, true );
76     }
77
78     public static PKIArchiveOptions getInstance( ASN1TaggedObject tagObj, boolean explicit )
79     {
80         int tag = tagObj.getTagNo();
81
82         switch (tag)
83         {
84           case 0: return new PKIArchiveOptions(EncryptedKey.getInstance(tagObj.getObject()), 0);
85           case 1: return new PKIArchiveOptions(DEROctetString.getInstance(tagObj.getObject()), 1);
86           case 2: return new PKIArchiveOptions(DERBoolean.getInstance(tagObj.getObject()), 2);
87         }
88
89         throw new IllegalArgumentException JavaDoc("unknown tag: " + tag);
90     }
91
92     public DERObject getDERObject()
93     {
94       return new DERTaggedObject(true, tag, obj);
95     }
96
97     public String JavaDoc toString()
98     {
99       return "PKIArchiveOptions: (" + obj + ")";
100     }
101 }
102
Popular Tags