package org.bouncycastle.asn1.x509; import java.math.BigInteger; import java.util.Enumeration; import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1Integer; import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.asn1.ASN1OctetString; import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.ASN1TaggedObject; import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.asn1.DERSequence; import org.bouncycastle.asn1.DERTaggedObject; import org.bouncycastle.crypto.digests.SHA1Digest; /* loaded from: classes6.dex */ public class AuthorityKeyIdentifier extends ASN1Object { GeneralNames certissuer; ASN1Integer certserno; ASN1OctetString keyidentifier; public String toString() { StringBuilder sb = new StringBuilder("AuthorityKeyIdentifier: KeyID("); sb.append(this.keyidentifier.getOctets()); sb.append(")"); return sb.toString(); } @Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable public ASN1Primitive toASN1Primitive() { ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector(); if (this.keyidentifier != null) { aSN1EncodableVector.add(new DERTaggedObject(false, 0, this.keyidentifier)); } if (this.certissuer != null) { aSN1EncodableVector.add(new DERTaggedObject(false, 1, this.certissuer)); } if (this.certserno != null) { aSN1EncodableVector.add(new DERTaggedObject(false, 2, this.certserno)); } return new DERSequence(aSN1EncodableVector); } public byte[] getKeyIdentifier() { ASN1OctetString aSN1OctetString = this.keyidentifier; if (aSN1OctetString != null) { return aSN1OctetString.getOctets(); } return null; } public BigInteger getAuthorityCertSerialNumber() { ASN1Integer aSN1Integer = this.certserno; if (aSN1Integer != null) { return aSN1Integer.getValue(); } return null; } public GeneralNames getAuthorityCertIssuer() { return this.certissuer; } public static AuthorityKeyIdentifier getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) { return getInstance(ASN1Sequence.getInstance(aSN1TaggedObject, z)); } public static AuthorityKeyIdentifier getInstance(Object obj) { if (obj instanceof AuthorityKeyIdentifier) { return (AuthorityKeyIdentifier) obj; } if (obj != null) { return new AuthorityKeyIdentifier(ASN1Sequence.getInstance(obj)); } return null; } public static AuthorityKeyIdentifier fromExtensions(Extensions extensions) { return getInstance(extensions.getExtensionParsedValue(Extension.authorityKeyIdentifier)); } public AuthorityKeyIdentifier(byte[] bArr, GeneralNames generalNames, BigInteger bigInteger) { this.keyidentifier = null; this.certissuer = null; this.certserno = null; this.keyidentifier = bArr != null ? new DEROctetString(bArr) : null; this.certissuer = generalNames; this.certserno = bigInteger != null ? new ASN1Integer(bigInteger) : null; } public AuthorityKeyIdentifier(byte[] bArr) { this(bArr, (GeneralNames) null, (BigInteger) null); } public AuthorityKeyIdentifier(SubjectPublicKeyInfo subjectPublicKeyInfo, GeneralNames generalNames, BigInteger bigInteger) { this.keyidentifier = null; this.certissuer = null; this.certserno = null; SHA1Digest sHA1Digest = new SHA1Digest(); byte[] bArr = new byte[sHA1Digest.getDigestSize()]; byte[] bytes = subjectPublicKeyInfo.getPublicKeyData().getBytes(); sHA1Digest.update(bytes, 0, bytes.length); sHA1Digest.doFinal(bArr, 0); this.keyidentifier = new DEROctetString(bArr); this.certissuer = GeneralNames.getInstance(generalNames.toASN1Primitive()); this.certserno = new ASN1Integer(bigInteger); } public AuthorityKeyIdentifier(SubjectPublicKeyInfo subjectPublicKeyInfo) { this.keyidentifier = null; this.certissuer = null; this.certserno = null; SHA1Digest sHA1Digest = new SHA1Digest(); byte[] bArr = new byte[sHA1Digest.getDigestSize()]; byte[] bytes = subjectPublicKeyInfo.getPublicKeyData().getBytes(); sHA1Digest.update(bytes, 0, bytes.length); sHA1Digest.doFinal(bArr, 0); this.keyidentifier = new DEROctetString(bArr); } public AuthorityKeyIdentifier(GeneralNames generalNames, BigInteger bigInteger) { this((byte[]) null, generalNames, bigInteger); } public AuthorityKeyIdentifier(ASN1Sequence aSN1Sequence) { this.keyidentifier = null; this.certissuer = null; this.certserno = null; Enumeration objects = aSN1Sequence.getObjects(); while (objects.hasMoreElements()) { ASN1TaggedObject dERTaggedObject = DERTaggedObject.getInstance(objects.nextElement()); int tagNo = dERTaggedObject.getTagNo(); if (tagNo == 0) { this.keyidentifier = ASN1OctetString.getInstance(dERTaggedObject, false); } else if (tagNo == 1) { this.certissuer = GeneralNames.getInstance(dERTaggedObject, false); } else { if (tagNo != 2) { throw new IllegalArgumentException("illegal tag"); } this.certserno = ASN1Integer.getInstance(dERTaggedObject, false); } } } }