initial checkin
[org.ibex.nanogoat.git] / src / org / bouncycastle / asn1 / x509 / CertificateList.java
1
2 package org.bouncycastle.asn1.x509;
3
4 import org.bouncycastle.asn1.*;
5
6 /**
7  * PKIX RFC-2459
8  *
9  * The X.509 v2 CRL syntax is as follows.  For signature calculation,
10  * the data that is to be signed is ASN.1 DER encoded.
11  *
12  * <pre>
13  * CertificateList  ::=  SEQUENCE  {
14  *      tbsCertList          TBSCertList,
15  *      signatureAlgorithm   AlgorithmIdentifier,
16  *      signatureValue       BIT STRING  }
17  * </pre>
18  */
19 public class CertificateList
20     implements DEREncodable
21 {
22     TBSCertList            tbsCertList;
23     AlgorithmIdentifier    sigAlgId;
24     DERBitString           sig;
25
26     public static CertificateList getInstance(
27         ASN1TaggedObject obj,
28         boolean          explicit)
29     {
30         return getInstance(ASN1Sequence.getInstance(obj, explicit));
31     }
32
33     public static CertificateList getInstance(
34         Object  obj)
35     {
36         if (obj instanceof CertificateList)
37         {
38             return (CertificateList)obj;
39         }
40         else if (obj instanceof ASN1Sequence)
41         {
42             return new CertificateList((ASN1Sequence)obj);
43         }
44
45         throw new IllegalArgumentException("unknown object in factory");
46     }
47
48     public CertificateList(
49         ASN1Sequence seq)
50     {
51         tbsCertList = TBSCertList.getInstance(seq.getObjectAt(0));
52         sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
53         sig = (DERBitString)seq.getObjectAt(2);
54     }
55
56     public TBSCertList getTBSCertList()
57     {
58         return tbsCertList;
59     }
60
61     public TBSCertList.CRLEntry[] getRevokedCertificates()
62     {
63         return tbsCertList.getRevokedCertificates();
64     }
65
66     public AlgorithmIdentifier getSignatureAlgorithm()
67     {
68         return sigAlgId;
69     }
70
71     public DERBitString getSignature()
72     {
73         return sig;
74     }
75
76     public int getVersion()
77     {
78         return tbsCertList.getVersion();
79     }
80
81     public X509Name getIssuer()
82     {
83         return tbsCertList.getIssuer();
84     }
85
86     public Time getThisUpdate()
87     {
88         return tbsCertList.getThisUpdate();
89     }
90
91     public Time getNextUpdate()
92     {
93         return tbsCertList.getNextUpdate();
94     }
95
96     public DERObject getDERObject()
97     {
98         DERConstructedSequence seq = new DERConstructedSequence();
99         seq.addObject(tbsCertList);
100         seq.addObject(sigAlgId);
101         seq.addObject(sig);
102         return seq;
103     }
104 }