package org.bouncycastle.asn1.eac; import java.io.IOException; import org.bouncycastle.asn1.ASN1ApplicationSpecific; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.ASN1ParsingException; import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.DERApplicationSpecific; import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.util.Arrays; /* loaded from: classes6.dex */ public class CVCertificate extends ASN1Object { private static int bodyValid = 1; private static int signValid = 2; private CertificateBody certificateBody; private byte[] signature; private int valid; @Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable public ASN1Primitive toASN1Primitive() { ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector(); aSN1EncodableVector.add(this.certificateBody); try { aSN1EncodableVector.add(new DERApplicationSpecific(false, 55, (ASN1Encodable) new DEROctetString(this.signature))); return new DERApplicationSpecific(33, aSN1EncodableVector); } catch (IOException unused) { throw new IllegalStateException("unable to convert signature!"); } } public byte[] getSignature() { return Arrays.clone(this.signature); } public int getRole() throws IOException { return this.certificateBody.getCertificateHolderAuthorization().getAccessRights(); } public CertificateHolderReference getHolderReference() throws IOException { return this.certificateBody.getCertificateHolderReference(); } public int getHolderAuthorizationRole() throws IOException { return this.certificateBody.getCertificateHolderAuthorization().getAccessRights() & 192; } public Flags getHolderAuthorizationRights() throws IOException { return new Flags(this.certificateBody.getCertificateHolderAuthorization().getAccessRights() & 31); } public ASN1ObjectIdentifier getHolderAuthorization() throws IOException { return this.certificateBody.getCertificateHolderAuthorization().getOid(); } public PackedDate getExpirationDate() throws IOException { return this.certificateBody.getCertificateExpirationDate(); } public PackedDate getEffectiveDate() throws IOException { return this.certificateBody.getCertificateEffectiveDate(); } public int getCertificateType() { return this.certificateBody.getCertificateType(); } public CertificateBody getBody() { return this.certificateBody; } public CertificationAuthorityReference getAuthorityReference() throws IOException { return this.certificateBody.getCertificationAuthorityReference(); } private void setPrivateData(ASN1ApplicationSpecific aSN1ApplicationSpecific) throws IOException { int i; int i2; this.valid = 0; if (aSN1ApplicationSpecific.getApplicationTag() != 33) { StringBuilder sb = new StringBuilder("not a CARDHOLDER_CERTIFICATE :"); sb.append(aSN1ApplicationSpecific.getApplicationTag()); throw new IOException(sb.toString()); } ASN1InputStream aSN1InputStream = new ASN1InputStream(aSN1ApplicationSpecific.getContents()); while (true) { ASN1Primitive readObject = aSN1InputStream.readObject(); if (readObject == null) { aSN1InputStream.close(); if (this.valid == (signValid | bodyValid)) { return; } StringBuilder sb2 = new StringBuilder("invalid CARDHOLDER_CERTIFICATE :"); sb2.append(aSN1ApplicationSpecific.getApplicationTag()); throw new IOException(sb2.toString()); } if (!(readObject instanceof DERApplicationSpecific)) { throw new IOException("Invalid Object, not an Iso7816CertificateStructure"); } DERApplicationSpecific dERApplicationSpecific = (DERApplicationSpecific) readObject; int applicationTag = dERApplicationSpecific.getApplicationTag(); if (applicationTag == 55) { this.signature = dERApplicationSpecific.getContents(); i = this.valid; i2 = signValid; } else { if (applicationTag != 78) { StringBuilder sb3 = new StringBuilder("Invalid tag, not an Iso7816CertificateStructure :"); sb3.append(dERApplicationSpecific.getApplicationTag()); throw new IOException(sb3.toString()); } this.certificateBody = CertificateBody.getInstance(dERApplicationSpecific); i = this.valid; i2 = bodyValid; } this.valid = i | i2; } } private void initFrom(ASN1InputStream aSN1InputStream) throws IOException { while (true) { ASN1Primitive readObject = aSN1InputStream.readObject(); if (readObject == null) { return; } if (!(readObject instanceof DERApplicationSpecific)) { throw new IOException("Invalid Input Stream for creating an Iso7816CertificateStructure"); } setPrivateData((DERApplicationSpecific) readObject); } } public static CVCertificate getInstance(Object obj) { if (obj instanceof CVCertificate) { return (CVCertificate) obj; } if (obj == null) { return null; } try { return new CVCertificate(DERApplicationSpecific.getInstance(obj)); } catch (IOException e) { StringBuilder sb = new StringBuilder("unable to parse data: "); sb.append(e.getMessage()); throw new ASN1ParsingException(sb.toString(), e); } } public CVCertificate(CertificateBody certificateBody, byte[] bArr) throws IOException { this.certificateBody = certificateBody; this.signature = Arrays.clone(bArr); this.valid = this.valid | bodyValid | signValid; } public CVCertificate(ASN1InputStream aSN1InputStream) throws IOException { initFrom(aSN1InputStream); } private CVCertificate(ASN1ApplicationSpecific aSN1ApplicationSpecific) throws IOException { setPrivateData(aSN1ApplicationSpecific); } }