KickJava   Java API By Example, From Geeks To Geeks.

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


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.ASN1EncodableVector;
23 import org.bouncycastle.asn1.ASN1Sequence;
24 import org.bouncycastle.asn1.ASN1TaggedObject;
25 import org.bouncycastle.asn1.DERBitString;
26 import org.bouncycastle.asn1.DEREncodable;
27 import org.bouncycastle.asn1.DERObject;
28 import org.bouncycastle.asn1.DERSequence;
29 import org.bouncycastle.asn1.DERTaggedObject;
30 import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
31
32 /**
33  * ASN.1 structure DER En/DeCoder.
34  *
35  * <pre>
36  * POPOSigningKey ::= SEQUENCE {
37  * poposkInput [0] POPOSigningKeyInput OPTIONAL,
38  * algorithmIdentifier AlgorithmIdentifier,
39  * signature BIT STRING } -- The signature (using "algorithmIdentifier") is on the DER-encoded value of poposkInput. NOTE: If the CertReqMsg
40  * -- certReq CertTemplate contains the subject and publicKey values, then poposkInput MUST be omitted and the signature MUST be
41  * -- computed on the DER-encoded value of CertReqMsg certReq. If the CertReqMsg certReq CertTemplate does not contain the public
42  * -- key and subject values, then poposkInput MUST be present and MUST be signed. This strategy ensures that the public key is
43  * -- not present in both the poposkInput and CertReqMsg certReq CertTemplate fields.
44  *
45  * </pre>
46  */

47 public class POPOSigningKey implements DEREncodable
48 {
49     POPOSigningKeyInput poposkInput;
50     AlgorithmIdentifier algorithmIdentifier;
51     DERBitString signature;
52
53     public static POPOSigningKey getInstance( ASN1TaggedObject obj, boolean explicit )
54     {
55         return getInstance(ASN1Sequence.getInstance(obj, explicit));
56     }
57
58     public static POPOSigningKey getInstance( Object JavaDoc obj )
59     {
60         if (obj instanceof POPOSigningKey)
61         {
62             return (POPOSigningKey)obj;
63         }
64         else if (obj instanceof ASN1Sequence)
65         {
66             return new POPOSigningKey((ASN1Sequence)obj);
67         }
68
69         throw new IllegalArgumentException JavaDoc("unknown object in factory");
70     }
71     
72     public POPOSigningKey( ASN1Sequence seq )
73     {
74       int idx = 0;
75       Object JavaDoc obj = seq.getObjectAt(idx++);
76       
77       if( obj instanceof ASN1TaggedObject )
78       {
79         ASN1TaggedObject tagObj = (ASN1TaggedObject)obj;
80         if( tagObj.getTagNo() == 0 )
81           this.poposkInput = POPOSigningKeyInput.getInstance( tagObj.getObject() );
82         else
83           throw new IllegalArgumentException JavaDoc("unknown tag: " + tagObj.getTagNo());
84       }
85       else
86         idx--;
87         
88       this.algorithmIdentifier = AlgorithmIdentifier.getInstance( seq.getObjectAt(idx++) );
89       this.signature = DERBitString.getInstance( seq.getObjectAt(idx) );
90     }
91
92     public POPOSigningKey( AlgorithmIdentifier algorithmIdentifier, DERBitString signature )
93     {
94       this.algorithmIdentifier = algorithmIdentifier;
95       this.signature = signature;
96     }
97
98     public POPOSigningKeyInput getPoposkInput()
99     {
100       return poposkInput;
101     }
102
103     public void setPoposkInput( POPOSigningKeyInput poposkInput )
104     {
105       this.poposkInput = poposkInput;
106     }
107
108     public AlgorithmIdentifier getAlgorithmIdentifier()
109     {
110       return algorithmIdentifier;
111     }
112
113     public DERBitString getSignature()
114     {
115       return signature;
116     }
117
118     public DERObject getDERObject()
119     {
120       ASN1EncodableVector v = new ASN1EncodableVector();
121
122       if( poposkInput != null )
123         v.add( new DERTaggedObject( false, 0, poposkInput ) );
124
125       v.add( algorithmIdentifier );
126       v.add( signature );
127
128       return new DERSequence(v);
129     }
130
131     public String JavaDoc toString()
132     {
133       String JavaDoc s = "POPOSigningKey: (";
134       
135       if( this.getPoposkInput() != null )
136         s += "poposkInput: " + this.getPoposkInput() + ", ";
137
138       s += "algorithmIdentifier: " + this.getAlgorithmIdentifier() + ", ";
139         
140       s += "signature: " + this.getSignature() + ")";
141       
142       return s;
143     }
144 }
145
Popular Tags