package org.bouncycastle.x509.extension; import java.io.IOException; import java.security.InvalidKeyException; import java.security.PublicKey; import java.security.cert.CertificateParsingException; import java.security.cert.X509Certificate; import org.bouncycastle.asn1.ASN1OctetString; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier; import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.GeneralName; import org.bouncycastle.asn1.x509.GeneralNames; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.asn1.x509.X509Extension; import org.bouncycastle.jce.PrincipalUtil; /* loaded from: classes6.dex */ public class AuthorityKeyIdentifierStructure extends AuthorityKeyIdentifier { private static ASN1Sequence fromKey(PublicKey publicKey) throws InvalidKeyException { try { return (ASN1Sequence) new AuthorityKeyIdentifier(SubjectPublicKeyInfo.getInstance(publicKey.getEncoded())).toASN1Primitive(); } catch (Exception e) { throw new InvalidKeyException("can't process key: ".concat(String.valueOf(e))); } } private static ASN1Sequence fromCertificate(X509Certificate x509Certificate) throws CertificateParsingException { try { if (x509Certificate.getVersion() != 3) { return (ASN1Sequence) new AuthorityKeyIdentifier(SubjectPublicKeyInfo.getInstance(x509Certificate.getPublicKey().getEncoded()), new GeneralNames(new GeneralName(PrincipalUtil.getIssuerX509Principal(x509Certificate))), x509Certificate.getSerialNumber()).toASN1Primitive(); } GeneralName generalName = new GeneralName(PrincipalUtil.getIssuerX509Principal(x509Certificate)); byte[] extensionValue = x509Certificate.getExtensionValue(Extension.subjectKeyIdentifier.getId()); return extensionValue != null ? (ASN1Sequence) new AuthorityKeyIdentifier(((ASN1OctetString) X509ExtensionUtil.fromExtensionValue(extensionValue)).getOctets(), new GeneralNames(generalName), x509Certificate.getSerialNumber()).toASN1Primitive() : (ASN1Sequence) new AuthorityKeyIdentifier(SubjectPublicKeyInfo.getInstance(x509Certificate.getPublicKey().getEncoded()), new GeneralNames(generalName), x509Certificate.getSerialNumber()).toASN1Primitive(); } catch (Exception e) { StringBuilder sb = new StringBuilder("Exception extracting certificate details: "); sb.append(e.toString()); throw new CertificateParsingException(sb.toString()); } } public AuthorityKeyIdentifierStructure(byte[] bArr) throws IOException { super((ASN1Sequence) X509ExtensionUtil.fromExtensionValue(bArr)); } public AuthorityKeyIdentifierStructure(X509Extension x509Extension) { super((ASN1Sequence) x509Extension.getParsedValue()); } public AuthorityKeyIdentifierStructure(Extension extension) { super((ASN1Sequence) extension.getParsedValue()); } public AuthorityKeyIdentifierStructure(X509Certificate x509Certificate) throws CertificateParsingException { super(fromCertificate(x509Certificate)); } public AuthorityKeyIdentifierStructure(PublicKey publicKey) throws InvalidKeyException { super(fromKey(publicKey)); } }