001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1Sequence;
005: import org.bouncycastle.asn1.ASN1TaggedObject;
006: import org.bouncycastle.asn1.DERBitString;
007: import org.bouncycastle.asn1.DERInteger;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
010:
011: /**
012: * an X509Certificate structure.
013: * <pre>
014: * Certificate ::= SEQUENCE {
015: * tbsCertificate TBSCertificate,
016: * signatureAlgorithm AlgorithmIdentifier,
017: * signature BIT STRING
018: * }
019: * </pre>
020: */
021: public class X509CertificateStructure extends ASN1Encodable implements
022: X509ObjectIdentifiers, PKCSObjectIdentifiers {
023: ASN1Sequence seq;
024: TBSCertificateStructure tbsCert;
025: AlgorithmIdentifier sigAlgId;
026: DERBitString sig;
027:
028: public static X509CertificateStructure getInstance(
029: ASN1TaggedObject obj, boolean explicit) {
030: return getInstance(ASN1Sequence.getInstance(obj, explicit));
031: }
032:
033: public static X509CertificateStructure getInstance(Object obj) {
034: if (obj instanceof X509CertificateStructure) {
035: return (X509CertificateStructure) obj;
036: } else if (obj instanceof ASN1Sequence) {
037: return new X509CertificateStructure((ASN1Sequence) obj);
038: }
039:
040: throw new IllegalArgumentException("unknown object in factory");
041: }
042:
043: public X509CertificateStructure(ASN1Sequence seq) {
044: this .seq = seq;
045:
046: //
047: // correct x509 certficate
048: //
049: if (seq.size() == 3) {
050: tbsCert = TBSCertificateStructure.getInstance(seq
051: .getObjectAt(0));
052: sigAlgId = AlgorithmIdentifier.getInstance(seq
053: .getObjectAt(1));
054:
055: sig = DERBitString.getInstance(seq.getObjectAt(2));
056: } else {
057: throw new IllegalArgumentException(
058: "sequence wrong size for a certificate");
059: }
060: }
061:
062: public TBSCertificateStructure getTBSCertificate() {
063: return tbsCert;
064: }
065:
066: public int getVersion() {
067: return tbsCert.getVersion();
068: }
069:
070: public DERInteger getSerialNumber() {
071: return tbsCert.getSerialNumber();
072: }
073:
074: public X509Name getIssuer() {
075: return tbsCert.getIssuer();
076: }
077:
078: public Time getStartDate() {
079: return tbsCert.getStartDate();
080: }
081:
082: public Time getEndDate() {
083: return tbsCert.getEndDate();
084: }
085:
086: public X509Name getSubject() {
087: return tbsCert.getSubject();
088: }
089:
090: public SubjectPublicKeyInfo getSubjectPublicKeyInfo() {
091: return tbsCert.getSubjectPublicKeyInfo();
092: }
093:
094: public AlgorithmIdentifier getSignatureAlgorithm() {
095: return sigAlgId;
096: }
097:
098: public DERBitString getSignature() {
099: return sig;
100: }
101:
102: public DERObject toASN1Object() {
103: return seq;
104: }
105: }
|