KickJava   Java API By Example, From Geeks To Geeks.

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


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.ASN1Sequence;
24 import org.bouncycastle.asn1.ASN1TaggedObject;
25 import org.bouncycastle.asn1.DERBitString;
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  * PKIStatusInfo ::= SEQUENCE {
36  * status PKIStatus, (INTEGER)
37  * statusString PKIFreeText OPTIONAL,
38  * failInfo PKIFailureInfo OPTIONAL (BIT STRING)
39  * }
40  *
41  * PKIStatus:
42  * granted (0), -- you got exactly what you asked for
43  * grantedWithMods (1), -- you got something like what you asked for
44  * rejection (2), -- you don't get it, more information elsewhere in the message
45  * waiting (3), -- the request body part has not yet been processed, expect to hear more later
46  * revocationWarning (4), -- this message contains a warning that a revocation is imminent
47  * revocationNotification (5), -- notification that a revocation has occurred
48  * keyUpdateWarning (6) -- update already done for the oldCertId specified in CertReqMsg
49  *
50  * PKIFailureInfo:
51  * badAlg (0), -- unrecognized or unsupported Algorithm Identifier
52  * badMessageCheck (1), -- integrity check failed (e.g., signature did not verify)
53  * badRequest (2), -- transaction not permitted or supported
54  * badTime (3), -- messageTime was not sufficiently close to the system time, as defined by local policy
55  * badCertId (4), -- no certificate could be found matching the provided criteria
56  * badDataFormat (5), -- the data submitted has the wrong format
57  * wrongAuthority (6), -- the authority indicated in the request is different from the one creating the response token
58  * incorrectData (7), -- the requester's data is incorrect (for notary services)
59  * missingTimeStamp (8), -- when the timestamp is missing but should be there (by policy)
60  * badPOP (9) -- the proof-of-possession failed
61  *
62  * </pre>
63  */

64 public class PKIStatusInfo implements DEREncodable
65 {
66     DERInteger status;
67     PKIFreeText statusString;
68     DERBitString failInfo;
69
70     public static PKIStatusInfo getInstance( ASN1TaggedObject obj, boolean explicit )
71     {
72         return getInstance(ASN1Sequence.getInstance(obj, explicit));
73     }
74
75     public static PKIStatusInfo getInstance( Object JavaDoc obj )
76     {
77         if (obj instanceof PKIStatusInfo)
78         {
79             return (PKIStatusInfo)obj;
80         }
81         else if (obj instanceof ASN1Sequence)
82         {
83             return new PKIStatusInfo((ASN1Sequence)obj);
84         }
85
86         throw new IllegalArgumentException JavaDoc("unknown object in factory");
87     }
88     
89     public PKIStatusInfo( ASN1Sequence seq )
90     {
91         this.status = DERInteger.getInstance(seq.getObjectAt(0));
92
93         this.statusString = null;
94         this.failInfo = null;
95         
96         if (seq.size() > 2)
97         {
98           this.statusString = PKIFreeText.getInstance(seq.getObjectAt(1));
99           this.failInfo = DERBitString.getInstance(seq.getObjectAt(2));
100         }
101         else
102         if (seq.size() > 1)
103         {
104           Object JavaDoc obj = seq.getObjectAt(1);
105
106           if( obj instanceof ASN1Sequence )
107             this.statusString = PKIFreeText.getInstance(obj);
108           else
109             this.failInfo = DERBitString.getInstance(obj);
110         }
111     }
112     
113     public PKIStatusInfo( DERInteger status )
114     {
115       this.status = status;
116     }
117
118     public DERInteger getStatus()
119     {
120       return status;
121     }
122
123     public PKIFreeText getStatusString()
124     {
125       return statusString;
126     }
127
128     public void setStatusString(PKIFreeText statusString)
129     {
130       this.statusString = statusString;
131     }
132
133
134     public DERBitString getFailInfo()
135     {
136       return failInfo;
137     }
138
139     public void setFailInfo(DERBitString failInfo)
140     {
141       this.failInfo = failInfo;
142     }
143
144     public DERObject getDERObject()
145     {
146         ASN1EncodableVector v = new ASN1EncodableVector();
147
148         v.add( status );
149
150         if ( statusString != null )
151             v.add( statusString );
152
153         if ( failInfo!= null )
154             v.add( failInfo );
155
156         return new DERSequence(v);
157     }
158
159     public String JavaDoc toString()
160     {
161       String JavaDoc s = "PKIStatusInfo: (status = " + this.getStatus();
162       
163       if( this.getStatusString() != null )
164         s += ", statusString: " + this.getStatusString();
165
166       if( this.getFailInfo() != null )
167         s += ", failInfo: " + this.getFailInfo();
168
169       s += ")";
170       
171       return s;
172     }
173 }
174
Popular Tags