2002/03/21 01:19:32
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / X509CertificateStructure.java
diff --git a/src/org/bouncycastle/asn1/x509/X509CertificateStructure.java b/src/org/bouncycastle/asn1/x509/X509CertificateStructure.java
new file mode 100644 (file)
index 0000000..68479c5
--- /dev/null
@@ -0,0 +1,110 @@
+package org.bouncycastle.asn1.x509;
+
+import org.bouncycastle.asn1.*;
+import org.bouncycastle.asn1.pkcs.*;
+
+/**
+ * an X509Certificate structure.
+ * <pre>
+ *  Certificate ::= SEQUENCE {
+ *      tbsCertificate          TBSCertificate,
+ *      signatureAlgorithm      AlgorithmIdentifier,
+ *      signature               BIT STRING
+ *  }
+ * </pre>
+ */
+public class X509CertificateStructure
+    implements DEREncodable, X509ObjectIdentifiers, PKCSObjectIdentifiers
+{
+    DERConstructedSequence  seq;
+    TBSCertificateStructure tbsCert;
+    AlgorithmIdentifier     sigAlgId;
+    DERBitString            sig;
+
+    public X509CertificateStructure(
+        DERConstructedSequence  seq)
+    {
+        this.seq = seq;
+
+        //
+        // correct x509 certficate
+        //
+        if (seq.getSize() == 3)
+        {
+            if (seq.getObjectAt(0) instanceof TBSCertificateStructure)
+            {
+                tbsCert = (TBSCertificateStructure)seq.getObjectAt(0);
+            }
+            else
+            {
+                tbsCert = new TBSCertificateStructure((DERConstructedSequence)seq.getObjectAt(0));
+            }
+
+            if (seq.getObjectAt(1) instanceof AlgorithmIdentifier)
+            {
+                sigAlgId = (AlgorithmIdentifier)seq.getObjectAt(1);
+            }
+            else
+            {
+                sigAlgId = new AlgorithmIdentifier((DERConstructedSequence)seq.getObjectAt(1));
+            }
+
+            sig = (DERBitString)seq.getObjectAt(2);
+        }
+    }
+
+    public TBSCertificateStructure getTBSCertificate()
+    {
+        return tbsCert;
+    }
+
+    public int getVersion()
+    {
+        return tbsCert.getVersion();
+    }
+
+    public DERInteger getSerialNumber()
+    {
+        return tbsCert.getSerialNumber();
+    }
+
+    public X509Name getIssuer()
+    {
+        return tbsCert.getIssuer();
+    }
+
+    public DERUTCTime getStartDate()
+    {
+        return tbsCert.getStartDate();
+    }
+
+    public DERUTCTime getEndDate()
+    {
+        return tbsCert.getEndDate();
+    }
+
+    public X509Name getSubject()
+    {
+        return tbsCert.getSubject();
+    }
+
+    public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
+    {
+        return tbsCert.getSubjectPublicKeyInfo();
+    }
+
+    public AlgorithmIdentifier getSignatureAlgorithm()
+    {
+        return sigAlgId;
+    }
+
+    public DERBitString getSignature()
+    {
+        return sig;
+    }
+
+    public DERObject getDERObject()
+    {
+        return seq;
+    }
+}