KickJava   Java API By Example, From Geeks To Geeks.

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


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.DEREncodable;
26 import org.bouncycastle.asn1.DERObject;
27 import org.bouncycastle.asn1.DERSequence;
28 import org.bouncycastle.asn1.DERTaggedObject;
29 import org.bouncycastle.asn1.x509.GeneralName;
30 import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
31
32 /**
33  * ASN.1 structure DER En/DeCoder.
34  *
35  * <pre>
36  *
37  * POPOSigningKeyInput ::= SEQUENCE {
38  * authInfo CHOICE {
39  * sender [0] GeneralName, -- used only if an authenticated identity has been established for the sender (e.g., a DN from a previously-issued and currently-valid certificate
40  * publicKeyMAC PKMACValue }, -- used if no authenticated GeneralName currently exists for the sender; publicKeyMAC contains a password-based MAC on the DER-encoded value of publicKey
41  *
42  * publicKey SubjectPublicKeyInfo } -- from CertTemplate
43  *
44  * </pre>
45  */

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