2002/03/21 01:19:32
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / X509CertificateStructure.java
1 package org.bouncycastle.asn1.x509;
2
3 import org.bouncycastle.asn1.*;
4 import org.bouncycastle.asn1.pkcs.*;
5
6 /**
7  * an X509Certificate structure.
8  * <pre>
9  *  Certificate ::= SEQUENCE {
10  *      tbsCertificate          TBSCertificate,
11  *      signatureAlgorithm      AlgorithmIdentifier,
12  *      signature               BIT STRING
13  *  }
14  * </pre>
15  */
16 public class X509CertificateStructure
17     implements DEREncodable, X509ObjectIdentifiers, PKCSObjectIdentifiers
18 {
19     DERConstructedSequence  seq;
20     TBSCertificateStructure tbsCert;
21     AlgorithmIdentifier     sigAlgId;
22     DERBitString            sig;
23
24     public X509CertificateStructure(
25         DERConstructedSequence  seq)
26     {
27         this.seq = seq;
28
29         //
30         // correct x509 certficate
31         //
32         if (seq.getSize() == 3)
33         {
34             if (seq.getObjectAt(0) instanceof TBSCertificateStructure)
35             {
36                 tbsCert = (TBSCertificateStructure)seq.getObjectAt(0);
37             }
38             else
39             {
40                 tbsCert = new TBSCertificateStructure((DERConstructedSequence)seq.getObjectAt(0));
41             }
42
43             if (seq.getObjectAt(1) instanceof AlgorithmIdentifier)
44             {
45                 sigAlgId = (AlgorithmIdentifier)seq.getObjectAt(1);
46             }
47             else
48             {
49                 sigAlgId = new AlgorithmIdentifier((DERConstructedSequence)seq.getObjectAt(1));
50             }
51
52             sig = (DERBitString)seq.getObjectAt(2);
53         }
54     }
55
56     public TBSCertificateStructure getTBSCertificate()
57     {
58         return tbsCert;
59     }
60
61     public int getVersion()
62     {
63         return tbsCert.getVersion();
64     }
65
66     public DERInteger getSerialNumber()
67     {
68         return tbsCert.getSerialNumber();
69     }
70
71     public X509Name getIssuer()
72     {
73         return tbsCert.getIssuer();
74     }
75
76     public DERUTCTime getStartDate()
77     {
78         return tbsCert.getStartDate();
79     }
80
81     public DERUTCTime getEndDate()
82     {
83         return tbsCert.getEndDate();
84     }
85
86     public X509Name getSubject()
87     {
88         return tbsCert.getSubject();
89     }
90
91     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
92     {
93         return tbsCert.getSubjectPublicKeyInfo();
94     }
95
96     public AlgorithmIdentifier getSignatureAlgorithm()
97     {
98         return sigAlgId;
99     }
100
101     public DERBitString getSignature()
102     {
103         return sig;
104     }
105
106     public DERObject getDERObject()
107     {
108         return seq;
109     }
110 }