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