KickJava   Java API By Example, From Geeks To Geeks.

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


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.DEREncodable;
24 import org.bouncycastle.asn1.DERNull;
25 import org.bouncycastle.asn1.DERObject;
26 import org.bouncycastle.asn1.DERTaggedObject;
27
28 /**
29  * ASN.1 structure DER En/DeCoder.
30  *
31  * <pre>
32  * ProofOfPossession ::= CHOICE {
33  * raVerified [0] NULL, -- used if the RA has already verified that the requester is in possession of the private key
34  * signature [1] POPOSigningKey,
35  * keyEncipherment [2] POPOPrivKey,
36  * keyAgreement [3] POPOPrivKey }
37  *
38  * </pre>
39  */

40 public class ProofOfPossession implements DEREncodable
41 {
42     DEREncodable obj;
43     int tag;
44
45     public ProofOfPossession( DEREncodable obj, int tag )
46     {
47         this.obj = obj;
48         this.tag = tag;
49     }
50     
51     public DERNull getRaVerified()
52     {
53       if( this.tag != 0 )
54         return null;
55       return (DERNull)this.obj;
56     }
57
58     public POPOSigningKey getSignature()
59     {
60       if( this.tag != 1 )
61         return null;
62       return (POPOSigningKey)this.obj;
63     }
64
65     public POPOPrivKey getKeyEncipherment()
66     {
67       if( this.tag != 2 )
68         return null;
69       return (POPOPrivKey)this.obj;
70     }
71
72     public POPOPrivKey getKeyAgreement()
73     {
74       if( this.tag != 3 )
75         return null;
76       return (POPOPrivKey)this.obj;
77     }
78
79     public static ProofOfPossession getInstance( DERObject obj )
80     {
81       return getInstance( (ASN1TaggedObject)obj, true );
82     }
83
84     public static ProofOfPossession getInstance( ASN1TaggedObject tagObj, boolean explicit )
85     {
86         int tag = tagObj.getTagNo();
87
88         switch (tag)
89         {
90           case 0: return new ProofOfPossession(tagObj.getObject(), 0);
91           case 1: return new ProofOfPossession(POPOSigningKey.getInstance(tagObj.getObject()), 1);
92           case 2: return new ProofOfPossession(POPOPrivKey.getInstance(tagObj.getObject()), 2);
93           case 3: return new ProofOfPossession(POPOPrivKey.getInstance(tagObj.getObject()), 3);
94         }
95
96         throw new IllegalArgumentException JavaDoc("unknown tag: " + tag);
97     }
98
99     public DERObject getDERObject()
100     {
101       return new DERTaggedObject(true, tag, obj); //tag explicit since we are in a choice
102
}
103
104     public String JavaDoc toString()
105     {
106       return "ProofOfPossession: (" + obj + ")";
107     }
108 }
109
Popular Tags