KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Vector JavaDoc;
24
25 import org.bouncycastle.asn1.ASN1EncodableVector;
26 import org.bouncycastle.asn1.ASN1Sequence;
27 import org.bouncycastle.asn1.ASN1TaggedObject;
28 import org.bouncycastle.asn1.DEREncodable;
29 import org.bouncycastle.asn1.DERObject;
30 import org.bouncycastle.asn1.DERSequence;
31 import org.bouncycastle.asn1.DERTaggedObject;
32 import org.bouncycastle.asn1.x509.CertificateList;
33
34 import com.novosec.pkix.asn1.crmf.CertId;
35
36 /**
37  * ASN.1 structure DER En/DeCoder.
38  *
39  * <pre>
40  * RevRepContent ::= SEQUENCE {
41  * status SEQUENCE SIZE (1..MAX) OF PKIStatusInfo, -- in same order as was sent in RevReqContent
42  * revCerts [0] SEQUENCE SIZE (1..MAX) OF CertId OPTIONAL, -- IDs for which revocation was requested (same order as status)
43  * crls [1] SEQUENCE SIZE (1..MAX) OF CertificateList OPTIONAL -- the resulting CRLs (there may be more than one)
44  * }
45  *
46  * </pre>
47  */

48
49 public class RevRepContent implements DEREncodable
50 {
51     Vector JavaDoc status = new Vector JavaDoc();
52     Vector JavaDoc revCerts = new Vector JavaDoc();
53     Vector JavaDoc crls = new Vector JavaDoc();
54
55     public static RevRepContent getInstance( ASN1TaggedObject obj, boolean explicit )
56     {
57         return getInstance(ASN1Sequence.getInstance(obj, explicit));
58     }
59
60     public static RevRepContent getInstance( Object JavaDoc obj )
61     {
62         if (obj instanceof RevRepContent)
63         {
64             return (RevRepContent)obj;
65         }
66         else if (obj instanceof ASN1Sequence)
67         {
68             return new RevRepContent((ASN1Sequence)obj);
69         }
70
71         throw new IllegalArgumentException JavaDoc("unknown object in factory");
72     }
73
74     public RevRepContent( ASN1Sequence seq )
75     {
76       Enumeration JavaDoc e = seq.getObjects();
77       
78       Enumeration JavaDoc estatus = ((ASN1Sequence)e.nextElement()).getObjects();
79       while (estatus.hasMoreElements()) {
80         status.addElement( PKIStatusInfo.getInstance( estatus.nextElement() ) );
81       }
82       
83       while( e.hasMoreElements() )
84       {
85         DERTaggedObject obj = (DERTaggedObject)e.nextElement();
86
87         switch( obj.getTagNo() )
88         {
89           case 0:
90 // Enumeration erevcerts = ((ASN1Sequence)e.nextElement()).getObjects();
91
Enumeration JavaDoc erevcerts = ((ASN1Sequence)obj.getObject()).getObjects();
92             while (erevcerts.hasMoreElements()) {
93               revCerts.addElement( CertId.getInstance( erevcerts.nextElement() ) );
94             }
95             break;
96           case 1:
97 // Enumeration ecrls = ((ASN1Sequence)e.nextElement()).getObjects();
98
Enumeration JavaDoc ecrls = ((ASN1Sequence)obj.getObject()).getObjects();
99             while (ecrls.hasMoreElements()) {
100               crls.addElement( CertificateList.getInstance( ecrls.nextElement() ) );
101             }
102             break;
103         }
104       }
105     }
106
107     public RevRepContent(PKIStatusInfo pKIStatusInfo)
108     {
109       status.clear();
110       status.addElement( pKIStatusInfo );
111       revCerts.clear();
112       crls.clear();
113     }
114
115     public void addPKIStatusInfo( PKIStatusInfo pKIStatusInfo )
116     {
117       status.addElement( pKIStatusInfo );
118     }
119
120     public PKIStatusInfo getPKIStatusInfo( int nr )
121     {
122       if (status.size() > nr)
123         return (PKIStatusInfo)status.elementAt(nr);
124
125       return null;
126     }
127    
128     public void addRevCert( CertId certId )
129     {
130       revCerts.addElement( certId );
131     }
132
133     public CertId getRevCert( int nr )
134     {
135       if (revCerts.size() > nr)
136         return (CertId)revCerts.elementAt(nr);
137
138       return null;
139     }
140    
141     public void addCrl( CertificateList crl )
142     {
143       crls.addElement( crl );
144     }
145
146     public CertificateList getCrl( int nr )
147     {
148       if (crls.size() > nr)
149         return (CertificateList)crls.elementAt(nr);
150
151       return null;
152     }
153   
154     public DERObject getDERObject()
155     {
156         ASN1EncodableVector v = new ASN1EncodableVector();
157
158         ASN1EncodableVector statv = new ASN1EncodableVector();
159         for (int i=0;i<status.size();i++)
160           statv.add( (PKIStatusInfo)status.elementAt(i) );
161         v.add( new DERSequence( statv ) );
162
163         if( revCerts.size() > 0 )
164         {
165           ASN1EncodableVector revcv = new ASN1EncodableVector();
166           for (int i=0;i<revCerts.size();i++)
167             revcv.add( (CertId)revCerts.elementAt(i) );
168           v.add( new DERSequence( revcv ) );
169         }
170
171         if( crls.size() > 0 )
172         {
173           ASN1EncodableVector crlsv = new ASN1EncodableVector();
174           for (int i=0;i<crls.size();i++)
175             crlsv.add( (CertificateList)crls.elementAt(i) );
176           v.add( new DERSequence( crlsv ) );
177         }
178
179         return new DERSequence(v);
180     }
181
182     public String JavaDoc toString()
183     {
184       String JavaDoc s = "RevRepContent: (";
185
186       
187       if( status.size() > 0 )
188       {
189         s += "status: (";
190         
191         for (int i=0;i<status.size();i++)
192           s += (PKIStatusInfo)status.elementAt(i);
193           
194         s += "), ";
195       }
196       
197       if( revCerts.size() > 0 )
198       {
199         s += "revCerts: (";
200
201         for (int i=0;i<revCerts.size();i++)
202           s += (CertId)revCerts.elementAt(i);
203
204         s += "), ";
205       }
206      
207       if( crls.size() > 0 )
208       {
209         s += "crls: (";
210   
211         for (int i=0;i<crls.size();i++)
212           s += (CertificateList)crls.elementAt(i);
213   
214         s += ")";
215       }
216       
217       s += ")";
218         
219       return s;
220     }
221 }
222
Popular Tags