CertificateList.java revision e6bf3e8dfa2804891a82075cb469b736321b4827
1 2package org.bouncycastle.asn1.x509; 3 4import java.util.Enumeration; 5 6import org.bouncycastle.asn1.ASN1EncodableVector; 7import org.bouncycastle.asn1.ASN1Object; 8import org.bouncycastle.asn1.ASN1Primitive; 9import org.bouncycastle.asn1.ASN1Sequence; 10import org.bouncycastle.asn1.ASN1TaggedObject; 11import org.bouncycastle.asn1.DERBitString; 12import org.bouncycastle.asn1.DERSequence; 13import org.bouncycastle.asn1.x500.X500Name; 14 15/** 16 * PKIX RFC-2459 17 * 18 * The X.509 v2 CRL syntax is as follows. For signature calculation, 19 * the data that is to be signed is ASN.1 DER encoded. 20 * 21 * <pre> 22 * CertificateList ::= SEQUENCE { 23 * tbsCertList TBSCertList, 24 * signatureAlgorithm AlgorithmIdentifier, 25 * signatureValue BIT STRING } 26 * </pre> 27 */ 28public class CertificateList 29 extends ASN1Object 30{ 31 TBSCertList tbsCertList; 32 AlgorithmIdentifier sigAlgId; 33 DERBitString sig; 34 35 public static CertificateList getInstance( 36 ASN1TaggedObject obj, 37 boolean explicit) 38 { 39 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 40 } 41 42 public static CertificateList getInstance( 43 Object obj) 44 { 45 if (obj instanceof CertificateList) 46 { 47 return (CertificateList)obj; 48 } 49 else if (obj != null) 50 { 51 return new CertificateList(ASN1Sequence.getInstance(obj)); 52 } 53 54 return null; 55 } 56 57 public CertificateList( 58 ASN1Sequence seq) 59 { 60 if (seq.size() == 3) 61 { 62 tbsCertList = TBSCertList.getInstance(seq.getObjectAt(0)); 63 sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); 64 sig = DERBitString.getInstance(seq.getObjectAt(2)); 65 } 66 else 67 { 68 throw new IllegalArgumentException("sequence wrong size for CertificateList"); 69 } 70 } 71 72 public TBSCertList getTBSCertList() 73 { 74 return tbsCertList; 75 } 76 77 public TBSCertList.CRLEntry[] getRevokedCertificates() 78 { 79 return tbsCertList.getRevokedCertificates(); 80 } 81 82 public Enumeration getRevokedCertificateEnumeration() 83 { 84 return tbsCertList.getRevokedCertificateEnumeration(); 85 } 86 87 public AlgorithmIdentifier getSignatureAlgorithm() 88 { 89 return sigAlgId; 90 } 91 92 public DERBitString getSignature() 93 { 94 return sig; 95 } 96 97 public int getVersionNumber() 98 { 99 return tbsCertList.getVersionNumber(); 100 } 101 102 public X500Name getIssuer() 103 { 104 return tbsCertList.getIssuer(); 105 } 106 107 public Time getThisUpdate() 108 { 109 return tbsCertList.getThisUpdate(); 110 } 111 112 public Time getNextUpdate() 113 { 114 return tbsCertList.getNextUpdate(); 115 } 116 117 public ASN1Primitive toASN1Primitive() 118 { 119 ASN1EncodableVector v = new ASN1EncodableVector(); 120 121 v.add(tbsCertList); 122 v.add(sigAlgId); 123 v.add(sig); 124 125 return new DERSequence(v); 126 } 127} 128