// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.asn1.x509;

import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.ASN1BitString;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1Object;

public class Certificate extends ASN1Object
{
    ASN1Sequence seq;
    TBSCertificate tbsCert;
    AlgorithmIdentifier sigAlgId;
    ASN1BitString sig;
    
    public static Certificate getInstance(final ASN1TaggedObject asn1TaggedObject, final boolean b) {
        return getInstance(ASN1Sequence.getInstance(asn1TaggedObject, b));
    }
    
    public static Certificate getInstance(final Object o) {
        if (o instanceof Certificate) {
            return (Certificate)o;
        }
        if (o != null) {
            return new Certificate(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    private Certificate(final ASN1Sequence seq) {
        this.seq = seq;
        if (seq.size() == 3) {
            this.tbsCert = TBSCertificate.getInstance(seq.getObjectAt(0));
            this.sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
            this.sig = ASN1BitString.getInstance(seq.getObjectAt(2));
            return;
        }
        throw new IllegalArgumentException("sequence wrong size for a certificate");
    }
    
    public Certificate(final TBSCertificate tbsCert, final AlgorithmIdentifier sigAlgId, final ASN1BitString sig) {
        if (tbsCert == null) {
            throw new NullPointerException("'tbsCertificate' cannot be null");
        }
        if (sigAlgId == null) {
            throw new NullPointerException("'signatureAlgorithm' cannot be null");
        }
        if (sig == null) {
            throw new NullPointerException("'signature' cannot be null");
        }
        this.tbsCert = tbsCert;
        this.sigAlgId = sigAlgId;
        this.sig = sig;
        final ASN1EncodableVector asn1EncodableVector = new ASN1EncodableVector(3);
        asn1EncodableVector.add(tbsCert);
        asn1EncodableVector.add(sigAlgId);
        asn1EncodableVector.add(sig);
        this.seq = new DERSequence(asn1EncodableVector);
    }
    
    public TBSCertificate getTBSCertificate() {
        return this.tbsCert;
    }
    
    public ASN1Integer getVersion() {
        return this.tbsCert.getVersion();
    }
    
    public int getVersionNumber() {
        return this.tbsCert.getVersionNumber();
    }
    
    public ASN1Integer getSerialNumber() {
        return this.tbsCert.getSerialNumber();
    }
    
    public X500Name getIssuer() {
        return this.tbsCert.getIssuer();
    }
    
    public Validity getValidity() {
        return this.tbsCert.getValidity();
    }
    
    public Time getStartDate() {
        return this.tbsCert.getStartDate();
    }
    
    public Time getEndDate() {
        return this.tbsCert.getEndDate();
    }
    
    public X500Name getSubject() {
        return this.tbsCert.getSubject();
    }
    
    public SubjectPublicKeyInfo getSubjectPublicKeyInfo() {
        return this.tbsCert.getSubjectPublicKeyInfo();
    }
    
    public ASN1BitString getIssuerUniqueID() {
        return this.tbsCert.getIssuerUniqueId();
    }
    
    public ASN1BitString getSubjectUniqueID() {
        return this.tbsCert.getSubjectUniqueId();
    }
    
    public Extensions getExtensions() {
        return this.tbsCert.getExtensions();
    }
    
    public AlgorithmIdentifier getSignatureAlgorithm() {
        return this.sigAlgId;
    }
    
    public ASN1BitString getSignature() {
        return this.sig;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return this.seq;
    }
}
