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