KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > cmp > CertResponse


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.cmp;
21
22 import java.util.Enumeration JavaDoc;
23
24 import org.bouncycastle.asn1.ASN1EncodableVector;
25 import org.bouncycastle.asn1.ASN1Sequence;
26 import org.bouncycastle.asn1.ASN1TaggedObject;
27 import org.bouncycastle.asn1.DEREncodable;
28 import org.bouncycastle.asn1.DERInteger;
29 import org.bouncycastle.asn1.DERObject;
30 import org.bouncycastle.asn1.DEROctetString;
31 import org.bouncycastle.asn1.DERSequence;
32
33 /**
34  * ASN.1 structure DER En/DeCoder.
35  *
36  * <pre>
37  * CertResponse ::= SEQUENCE {
38  * certReqId INTEGER, -- to match this response with corresponding request (a value of -1 is to be used if certReqId is not specified in the corresponding request)
39  * status PKIStatusInfo,
40  * certifiedKeyPair CertifiedKeyPair OPTIONAL,
41  * rspInfo OCTET STRING OPTIONAL -- analogous to the id-regInfo-asciiPairs OCTET STRING defined for regInfo in CertReqMsg [CRMF]
42  * }
43  *
44  * </pre>
45  */

46 public class CertResponse implements DEREncodable
47 {
48     DERInteger certReqId;
49     PKIStatusInfo status;
50     CertifiedKeyPair certifiedKeyPair;
51     DEROctetString rspInfo;
52
53     public static CertResponse getInstance( ASN1TaggedObject obj, boolean explicit )
54     {
55         return getInstance(ASN1Sequence.getInstance(obj, explicit));
56     }
57
58     public static CertResponse getInstance( Object JavaDoc obj )
59     {
60         if (obj instanceof CertResponse)
61         {
62             return (CertResponse)obj;
63         }
64         else if (obj instanceof ASN1Sequence)
65         {
66             return new CertResponse((ASN1Sequence)obj);
67         }
68
69         throw new IllegalArgumentException JavaDoc("unknown object in factory");
70     }
71     
72     public CertResponse( ASN1Sequence seq )
73     {
74       Enumeration JavaDoc e = seq.getObjects();
75
76       certReqId = DERInteger.getInstance( e.nextElement() );
77       status = PKIStatusInfo.getInstance( e.nextElement() );
78       
79       Object JavaDoc obj = null;
80       
81       if( e.hasMoreElements() )
82         obj = e.nextElement();
83       
84       if ( obj instanceof ASN1Sequence )
85       {
86         certifiedKeyPair = CertifiedKeyPair.getInstance( obj );
87
88         if( e.hasMoreElements() )
89           obj = e.nextElement();
90       }
91       
92       if( obj instanceof DEROctetString )
93         rspInfo = (DEROctetString)obj;
94     }
95
96     public CertResponse( DERInteger certReqId, PKIStatusInfo status )
97     {
98       this.certReqId = certReqId;
99       this.status = status;
100     }
101
102     public DERInteger getCertReqId()
103     {
104         return certReqId;
105     }
106     
107     public PKIStatusInfo getStatus()
108     {
109         return status;
110     }
111     
112     public void setCertifiedKeyPair( CertifiedKeyPair certifiedKeyPair )
113     {
114       this.certifiedKeyPair = certifiedKeyPair;
115     }
116
117     public CertifiedKeyPair getCertifiedKeyPair()
118     {
119       return certifiedKeyPair;
120     }
121
122     public void setRspInfo( DEROctetString rspInfo )
123     {
124       this.rspInfo = rspInfo;
125     }
126
127     public DEROctetString getRspInfo()
128     {
129       return rspInfo;
130     }
131
132     public DERObject getDERObject()
133     {
134       ASN1EncodableVector v = new ASN1EncodableVector();
135
136       v.add( certReqId );
137       v.add( status );
138       
139       if( certifiedKeyPair != null )
140         v.add( certifiedKeyPair );
141
142       if( rspInfo != null )
143         v.add( rspInfo );
144       
145       return new DERSequence(v);
146     }
147
148     public String JavaDoc toString()
149     {
150       String JavaDoc s = "CertResponse: ( certReqId: " + this.getCertReqId() + ", status: "+ this.getStatus() + ", ";
151
152       if( this.getCertifiedKeyPair() != null )
153         s += "certifiedKeyPair: "+ this.getCertifiedKeyPair() + ", ";
154
155       if( this.getRspInfo() != null )
156         s += "rspInfo: "+ this.getRspInfo() + ", ";
157
158       s += ")";
159       
160       return s;
161     }
162 }
163
Popular Tags