KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.bouncycastle.asn1.ASN1EncodableVector;
23 import org.bouncycastle.asn1.ASN1OctetString;
24 import org.bouncycastle.asn1.ASN1Sequence;
25 import org.bouncycastle.asn1.ASN1TaggedObject;
26 import org.bouncycastle.asn1.DEREncodable;
27 import org.bouncycastle.asn1.DERInteger;
28 import org.bouncycastle.asn1.DERObject;
29 import org.bouncycastle.asn1.DERSequence;
30
31 /**
32  * ASN.1 structure DER En/DeCoder.
33  *
34  * <pre>
35  * CertConfirmContent ::= SEQUENCE OF CertStatus
36  *
37  * CertStatus ::= SEQUENCE {
38  * certHash OCTET STRING,
39  * certReqId INTEGER,
40  * statusInfo PKIStatusInfo OPTIONAL
41  * }
42  *
43  * </pre>
44  */

45 public class CertConfirmContent implements DEREncodable
46 {
47     ASN1OctetString certHash;
48     DERInteger certReqId;
49     PKIStatusInfo statusInfo;
50
51     public static CertConfirmContent getInstance( ASN1TaggedObject obj, boolean explicit )
52     {
53         return getInstance(ASN1Sequence.getInstance(obj, explicit));
54     }
55
56     public static CertConfirmContent getInstance( Object JavaDoc obj )
57     {
58         if (obj instanceof CertConfirmContent)
59         {
60             return (CertConfirmContent)obj;
61         }
62         else if (obj instanceof ASN1Sequence)
63         {
64             return new CertConfirmContent((ASN1Sequence)obj);
65         }
66
67         throw new IllegalArgumentException JavaDoc("unknown object in factory");
68     }
69     
70     public CertConfirmContent( ASN1Sequence seq )
71     {
72         ASN1Sequence s = ASN1Sequence.getInstance(seq.getObjectAt(0));
73         
74         this.certHash = ASN1OctetString.getInstance( s.getObjectAt(0) );
75         this.certReqId = DERInteger.getInstance( s.getObjectAt(1) );
76         this.statusInfo = null;
77         
78         if( s.size() > 2 )
79         {
80             this.statusInfo = PKIStatusInfo.getInstance( s.getObjectAt(2) );
81         }
82     }
83
84     public CertConfirmContent( ASN1OctetString certHash, DERInteger certReqId)
85     {
86         this.certHash = certHash;
87         this.certReqId = certReqId;
88         this.statusInfo = null;
89     }
90
91     public DERInteger getCertReqId()
92     {
93       return certReqId;
94     }
95
96     public ASN1OctetString getCertHash()
97     {
98       return certHash;
99     }
100
101     public PKIStatusInfo getPKIStatus()
102     {
103       return statusInfo;
104     }
105
106     public void setPKIStatus(PKIStatusInfo status)
107     {
108       this.statusInfo = status;
109     }
110
111     public DERObject getDERObject()
112     {
113         ASN1EncodableVector outer = new ASN1EncodableVector();
114         ASN1EncodableVector v = new ASN1EncodableVector();
115
116         v.add( certHash );
117         v.add( certReqId );
118
119         if ( statusInfo != null )
120             v.add( statusInfo);
121
122         outer.add( new DERSequence(v) );
123         
124         return new DERSequence(outer);
125     }
126
127     public String JavaDoc toString()
128     {
129       String JavaDoc s = "CertConfirmContent: (certHash = " + this.getCertHash() +
130             ", certReqId = " + this.getCertReqId();
131       
132       if( this.getPKIStatus() != null )
133         s += "pkiStatus = " + this.getPKIStatus();
134         
135       s += ")";
136       
137       return s;
138     }
139 }
140
Popular Tags