1 20 package com.novosec.pkix.asn1.cmp; 21 22 import java.util.Enumeration ; 23 import java.util.Vector ; 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 48 49 public class RevRepContent implements DEREncodable 50 { 51 Vector status = new Vector (); 52 Vector revCerts = new Vector (); 53 Vector crls = new Vector (); 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 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 ("unknown object in factory"); 72 } 73 74 public RevRepContent( ASN1Sequence seq ) 75 { 76 Enumeration e = seq.getObjects(); 77 78 Enumeration 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)obj.getObject()).getObjects(); 92 while (erevcerts.hasMoreElements()) { 93 revCerts.addElement( CertId.getInstance( erevcerts.nextElement() ) ); 94 } 95 break; 96 case 1: 97 Enumeration 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 toString() 183 { 184 String 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 |