KickJava   Java API By Example, From Geeks To Geeks.

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


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.DERGeneralizedTime;
28 import org.bouncycastle.asn1.DERObject;
29 import org.bouncycastle.asn1.DERSequence;
30 import org.bouncycastle.asn1.x509.X509Extensions;
31
32 import com.novosec.pkix.asn1.crmf.CertTemplate;
33
34 /**
35  * ASN.1 structure DER En/DeCoder.
36  *
37  * <pre>
38  * RevDetails ::= SEQUENCE {
39  * certDetails CertTemplate, -- allows requester to specify as much as they can about the cert. for which revocation is requested
40  * revocationReason ReasonFlags OPTIONAL, -- the reason that revocation is requested
41  * badSinceDate GeneralizedTime OPTIONAL, -- indicates best knowledge of sender
42  * crlEntryDetails Extensions OPTIONAL -- requested crlEntryExtensions (X509Extensions)
43  * }
44  *
45  * ReasonFlags ::= BIT STRING {
46  * unused(0),
47  * keyCompromise(1),
48  * caCompromise(2),
49  * affiliationChanged(3),
50  * superseded(4),
51  * cessationOfOperation(5),
52  * certificateHold(6)
53  * }
54  *
55  * </pre>
56  */

57 public class RevDetails implements DEREncodable
58 {
59      CertTemplate certDetails;
60      DERBitString revocationReason;
61      DERGeneralizedTime badSinceDate;
62      X509Extensions crlEntryDetails;
63
64     public static RevDetails getInstance( ASN1TaggedObject obj, boolean explicit )
65     {
66         return getInstance(ASN1Sequence.getInstance(obj, explicit));
67     }
68
69     public static RevDetails getInstance( Object JavaDoc obj )
70     {
71         if (obj instanceof RevDetails)
72         {
73             return (RevDetails)obj;
74         }
75         else if (obj instanceof ASN1Sequence)
76         {
77             return new RevDetails((ASN1Sequence)obj);
78         }
79
80         throw new IllegalArgumentException JavaDoc("unknown object in factory");
81     }
82     
83     public RevDetails( ASN1Sequence seq )
84     {
85       this.certDetails = CertTemplate.getInstance( seq.getObjectAt(0) );
86       
87       int idx = 1;
88       
89       Object JavaDoc obj = null;
90       
91       if( idx < seq.size() )
92         obj = seq.getObjectAt(idx++);
93       
94       if( obj instanceof DERBitString )
95       {
96         this.revocationReason = DERBitString.getInstance( obj );
97         if( idx < seq.size() )
98           obj = seq.getObjectAt(idx++);
99         else
100           obj = null;
101       }
102     
103       if( obj instanceof DERGeneralizedTime )
104       {
105         this.badSinceDate = DERGeneralizedTime.getInstance( obj );
106         if( idx < seq.size() )
107           obj = seq.getObjectAt(idx++);
108         else
109           obj = null;
110       }
111     
112       if( obj instanceof ASN1Sequence )
113       {
114         this.crlEntryDetails = X509Extensions.getInstance( obj );
115         if( idx < seq.size() )
116           obj = seq.getObjectAt(idx++);
117         else
118           obj = null;
119       }
120
121       if( obj != null )
122         throw new IllegalArgumentException JavaDoc("unknown object in factory");
123     }
124
125     public RevDetails( CertTemplate certDetails )
126     {
127       this.certDetails = certDetails;
128       this.revocationReason = null;
129       this.badSinceDate = null;
130       this.crlEntryDetails = null;
131     }
132
133     public CertTemplate getCertDetails()
134     {
135         return certDetails;
136     }
137
138     public void setCertDetails( CertTemplate certDetails )
139     {
140         this.certDetails = certDetails;
141     }
142
143     public DERBitString getRevocationReason()
144     {
145         return revocationReason;
146     }
147
148     public void setRevocationReason( DERBitString revocationReason )
149     {
150         this.revocationReason = revocationReason;
151     }
152
153     public DERGeneralizedTime getBadSinceDate()
154     {
155         return badSinceDate;
156     }
157
158     public void setBadSinceDate( DERGeneralizedTime badSinceDate )
159     {
160         this.badSinceDate = badSinceDate;
161     }
162
163     public X509Extensions getCrlEntryDetails()
164     {
165         return crlEntryDetails;
166     }
167
168     public void setCrlEntryDetails( X509Extensions crlEntryDetails )
169     {
170         this.crlEntryDetails = crlEntryDetails;
171     }
172     
173     public DERObject getDERObject()
174     {
175         ASN1EncodableVector v = new ASN1EncodableVector();
176
177         v.add( certDetails );
178
179         if ( revocationReason != null )
180             v.add( revocationReason );
181
182         if ( badSinceDate!= null)
183             v.add( badSinceDate );
184
185         if ( crlEntryDetails!= null)
186             v.add( crlEntryDetails );
187
188         return new DERSequence(v);
189     }
190
191     public String JavaDoc toString()
192     {
193       String JavaDoc s = "RevDetails: ( certDetails = " + this.getCertDetails() + ", ";
194       
195       if( this.getRevocationReason() != null )
196        s += "revocationReason = " + this.getRevocationReason() + ", ";
197       
198       if( this.getBadSinceDate() != null )
199        s += "badSinceDate = " + this.getBadSinceDate() + ", ";
200       
201       if( this.getCrlEntryDetails() != null )
202        s += "crlEntryDetails = " + this.getCrlEntryDetails() + ", ";
203       
204       s += ")";
205       
206       return s;
207     }
208 }
209
Popular Tags