Home | History | Annotate | Download | only in x509
      1 package org.bouncycastle.asn1.x509;
      2 
      3 import org.bouncycastle.asn1.ASN1Integer;
      4 import org.bouncycastle.asn1.ASN1Object;
      5 import org.bouncycastle.asn1.ASN1Primitive;
      6 import org.bouncycastle.asn1.ASN1Sequence;
      7 import org.bouncycastle.asn1.ASN1TaggedObject;
      8 import org.bouncycastle.asn1.DERBitString;
      9 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
     10 import org.bouncycastle.asn1.x500.X500Name;
     11 
     12 /**
     13  * an X509Certificate structure.
     14  * <pre>
     15  *  Certificate ::= SEQUENCE {
     16  *      tbsCertificate          TBSCertificate,
     17  *      signatureAlgorithm      AlgorithmIdentifier,
     18  *      signature               BIT STRING
     19  *  }
     20  * </pre>
     21  * @deprecated use org.bouncycastle.asn1.x509.Certificate
     22  */
     23 public class X509CertificateStructure
     24     extends ASN1Object
     25     implements X509ObjectIdentifiers, PKCSObjectIdentifiers
     26 {
     27     ASN1Sequence  seq;
     28     TBSCertificateStructure tbsCert;
     29     AlgorithmIdentifier     sigAlgId;
     30     DERBitString            sig;
     31 
     32     public static X509CertificateStructure getInstance(
     33         ASN1TaggedObject obj,
     34         boolean          explicit)
     35     {
     36         return getInstance(ASN1Sequence.getInstance(obj, explicit));
     37     }
     38 
     39     public static X509CertificateStructure getInstance(
     40         Object  obj)
     41     {
     42         if (obj instanceof X509CertificateStructure)
     43         {
     44             return (X509CertificateStructure)obj;
     45         }
     46         else if (obj != null)
     47         {
     48             return new X509CertificateStructure(ASN1Sequence.getInstance(obj));
     49         }
     50 
     51         return null;
     52     }
     53 
     54     public X509CertificateStructure(
     55         ASN1Sequence  seq)
     56     {
     57         this.seq = seq;
     58 
     59         //
     60         // correct x509 certficate
     61         //
     62         if (seq.size() == 3)
     63         {
     64             tbsCert = TBSCertificateStructure.getInstance(seq.getObjectAt(0));
     65             sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
     66 
     67             sig = DERBitString.getInstance(seq.getObjectAt(2));
     68         }
     69         else
     70         {
     71             throw new IllegalArgumentException("sequence wrong size for a certificate");
     72         }
     73     }
     74 
     75     public TBSCertificateStructure getTBSCertificate()
     76     {
     77         return tbsCert;
     78     }
     79 
     80     public int getVersion()
     81     {
     82         return tbsCert.getVersion();
     83     }
     84 
     85     public ASN1Integer getSerialNumber()
     86     {
     87         return tbsCert.getSerialNumber();
     88     }
     89 
     90     public X500Name getIssuer()
     91     {
     92         return tbsCert.getIssuer();
     93     }
     94 
     95     public Time getStartDate()
     96     {
     97         return tbsCert.getStartDate();
     98     }
     99 
    100     public Time getEndDate()
    101     {
    102         return tbsCert.getEndDate();
    103     }
    104 
    105     public X500Name getSubject()
    106     {
    107         return tbsCert.getSubject();
    108     }
    109 
    110     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
    111     {
    112         return tbsCert.getSubjectPublicKeyInfo();
    113     }
    114 
    115     public AlgorithmIdentifier getSignatureAlgorithm()
    116     {
    117         return sigAlgId;
    118     }
    119 
    120     public DERBitString getSignature()
    121     {
    122         return sig;
    123     }
    124 
    125     public ASN1Primitive toASN1Primitive()
    126     {
    127         return seq;
    128     }
    129 }
    130