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    boolean                isHashCodeSet = false;
35    int                    hashCodeValue;
36
37    public static CertificateList getInstance(
38        ASN1TaggedObject obj,
39        boolean          explicit)
40    {
41        return getInstance(ASN1Sequence.getInstance(obj, explicit));
42    }
43
44    public static CertificateList getInstance(
45        Object  obj)
46    {
47        if (obj instanceof CertificateList)
48        {
49            return (CertificateList)obj;
50        }
51        else if (obj != null)
52        {
53            return new CertificateList(ASN1Sequence.getInstance(obj));
54        }
55
56        return null;
57    }
58
59    /**
60     * @deprecated use getInstance() method.
61     * @param seq
62     */
63    public CertificateList(
64        ASN1Sequence seq)
65    {
66        if (seq.size() == 3)
67        {
68            tbsCertList = TBSCertList.getInstance(seq.getObjectAt(0));
69            sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
70            sig = DERBitString.getInstance(seq.getObjectAt(2));
71        }
72        else
73        {
74            throw new IllegalArgumentException("sequence wrong size for CertificateList");
75        }
76    }
77
78    public TBSCertList getTBSCertList()
79    {
80        return tbsCertList;
81    }
82
83    public TBSCertList.CRLEntry[] getRevokedCertificates()
84    {
85        return tbsCertList.getRevokedCertificates();
86    }
87
88    public Enumeration getRevokedCertificateEnumeration()
89    {
90        return tbsCertList.getRevokedCertificateEnumeration();
91    }
92
93    public AlgorithmIdentifier getSignatureAlgorithm()
94    {
95        return sigAlgId;
96    }
97
98    public DERBitString getSignature()
99    {
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}
145