1 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 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 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 ("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 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 ("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 toString() 192 { 193 String 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 |