001 002package org.apache.commons.ssl.org.bouncycastle.asn1.x509; 003 004import java.util.Enumeration; 005 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 010import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 011import org.apache.commons.ssl.org.bouncycastle.asn1.DERBitString; 012import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 013import org.apache.commons.ssl.org.bouncycastle.asn1.x500.X500Name; 014 015/** 016 * PKIX RFC-2459 017 * 018 * The X.509 v2 CRL syntax is as follows. For signature calculation, 019 * the data that is to be signed is ASN.1 DER encoded. 020 * 021 * <pre> 022 * CertificateList ::= SEQUENCE { 023 * tbsCertList TBSCertList, 024 * signatureAlgorithm AlgorithmIdentifier, 025 * signatureValue BIT STRING } 026 * </pre> 027 */ 028public class CertificateList 029 extends ASN1Object 030{ 031 TBSCertList tbsCertList; 032 AlgorithmIdentifier sigAlgId; 033 DERBitString sig; 034 boolean isHashCodeSet = false; 035 int hashCodeValue; 036 037 public static CertificateList getInstance( 038 ASN1TaggedObject obj, 039 boolean explicit) 040 { 041 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 042 } 043 044 public static CertificateList getInstance( 045 Object obj) 046 { 047 if (obj instanceof CertificateList) 048 { 049 return (CertificateList)obj; 050 } 051 else if (obj != null) 052 { 053 return new CertificateList(ASN1Sequence.getInstance(obj)); 054 } 055 056 return null; 057 } 058 059 /** 060 * @deprecated use getInstance() method. 061 * @param seq 062 */ 063 public CertificateList( 064 ASN1Sequence seq) 065 { 066 if (seq.size() == 3) 067 { 068 tbsCertList = TBSCertList.getInstance(seq.getObjectAt(0)); 069 sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); 070 sig = DERBitString.getInstance(seq.getObjectAt(2)); 071 } 072 else 073 { 074 throw new IllegalArgumentException("sequence wrong size for CertificateList"); 075 } 076 } 077 078 public TBSCertList getTBSCertList() 079 { 080 return tbsCertList; 081 } 082 083 public TBSCertList.CRLEntry[] getRevokedCertificates() 084 { 085 return tbsCertList.getRevokedCertificates(); 086 } 087 088 public Enumeration getRevokedCertificateEnumeration() 089 { 090 return tbsCertList.getRevokedCertificateEnumeration(); 091 } 092 093 public AlgorithmIdentifier getSignatureAlgorithm() 094 { 095 return sigAlgId; 096 } 097 098 public DERBitString getSignature() 099 { 100 return sig; 101 } 102 103 public int getVersionNumber() 104 { 105 return tbsCertList.getVersionNumber(); 106 } 107 108 public X500Name getIssuer() 109 { 110 return tbsCertList.getIssuer(); 111 } 112 113 public Time getThisUpdate() 114 { 115 return tbsCertList.getThisUpdate(); 116 } 117 118 public Time getNextUpdate() 119 { 120 return tbsCertList.getNextUpdate(); 121 } 122 123 public ASN1Primitive toASN1Primitive() 124 { 125 ASN1EncodableVector v = new ASN1EncodableVector(); 126 127 v.add(tbsCertList); 128 v.add(sigAlgId); 129 v.add(sig); 130 131 return new DERSequence(v); 132 } 133 134 public int hashCode() 135 { 136 if (!isHashCodeSet) 137 { 138 hashCodeValue = super.hashCode(); 139 isHashCodeSet = true; 140 } 141 142 return hashCodeValue; 143 } 144}