package org.bouncycastle.openpgp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.cryptlib.CryptlibObjectIdentifiers;
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
import org.bouncycastle.asn1.gnu.GNUObjectIdentifiers;
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
import org.bouncycastle.asn1.x9.X9ECParametersHolder;
import org.bouncycastle.bcpg.BCPGKey;
import org.bouncycastle.bcpg.BCPGOutputStream;
import org.bouncycastle.bcpg.DSAPublicBCPGKey;
import org.bouncycastle.bcpg.ECPublicBCPGKey;
import org.bouncycastle.bcpg.ElGamalPublicBCPGKey;
import org.bouncycastle.bcpg.KeyIdentifier;
import org.bouncycastle.bcpg.OctetArrayBCPGKey;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
import org.bouncycastle.bcpg.PublicKeyPacket;
import org.bouncycastle.bcpg.PublicSubkeyPacket;
import org.bouncycastle.bcpg.RSAPublicBCPGKey;
import org.bouncycastle.bcpg.TrustPacket;
import org.bouncycastle.bcpg.UserAttributePacket;
import org.bouncycastle.bcpg.UserDataPacket;
import org.bouncycastle.bcpg.UserIDPacket;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.bouncycastle.util.Arrays;

/* JADX INFO: loaded from: classes3.dex */
public class PGPPublicKey implements PublicKeyAlgorithmTags {
    private static final int[] MASTER_KEY_CERTIFICATION_TYPES = {19, 18, 17, 16, 31};
    List<List<PGPSignature>> idSigs;
    List<TrustPacket> idTrusts;
    List<UserDataPacket> ids;
    private KeyIdentifier keyIdentifier;
    List<PGPSignature> keySigs;
    private int keyStrength;
    PublicKeyPacket publicPk;
    List<PGPSignature> subSigs;
    TrustPacket trustPk;

    PGPPublicKey(PublicKeyPacket publicKeyPacket, TrustPacket trustPacket, List<PGPSignature> list, List<UserDataPacket> list2, List<TrustPacket> list3, List<List<PGPSignature>> list4, KeyFingerPrintCalculator keyFingerPrintCalculator) throws PGPException {
        this.keySigs = new ArrayList();
        this.ids = new ArrayList();
        this.idTrusts = new ArrayList();
        this.idSigs = new ArrayList();
        this.subSigs = null;
        this.publicPk = publicKeyPacket;
        this.trustPk = trustPacket;
        this.keySigs = list;
        this.ids = list2;
        this.idTrusts = list3;
        this.idSigs = list4;
        init(keyFingerPrintCalculator);
    }

    PGPPublicKey(PublicKeyPacket publicKeyPacket, TrustPacket trustPacket, List<PGPSignature> list, KeyFingerPrintCalculator keyFingerPrintCalculator) throws PGPException {
        this.keySigs = new ArrayList();
        this.ids = new ArrayList();
        this.idTrusts = new ArrayList();
        this.idSigs = new ArrayList();
        this.subSigs = null;
        this.publicPk = publicKeyPacket;
        this.trustPk = trustPacket;
        this.subSigs = list;
        init(keyFingerPrintCalculator);
    }

    public PGPPublicKey(PublicKeyPacket publicKeyPacket, KeyFingerPrintCalculator keyFingerPrintCalculator) throws PGPException {
        this.keySigs = new ArrayList();
        this.ids = new ArrayList();
        this.idTrusts = new ArrayList();
        this.idSigs = new ArrayList();
        this.subSigs = null;
        this.publicPk = publicKeyPacket;
        this.ids = new ArrayList();
        this.idSigs = new ArrayList();
        init(keyFingerPrintCalculator);
    }

    PGPPublicKey(PGPPublicKey pGPPublicKey) {
        this.keySigs = new ArrayList();
        this.ids = new ArrayList();
        this.idTrusts = new ArrayList();
        this.idSigs = new ArrayList();
        this.subSigs = null;
        this.publicPk = pGPPublicKey.publicPk;
        this.keySigs = new ArrayList(pGPPublicKey.keySigs);
        this.ids = new ArrayList(pGPPublicKey.ids);
        this.idTrusts = new ArrayList(pGPPublicKey.idTrusts);
        this.idSigs = new ArrayList(pGPPublicKey.idSigs.size());
        for (int i = 0; i != pGPPublicKey.idSigs.size(); i++) {
            this.idSigs.add(new ArrayList(pGPPublicKey.idSigs.get(i)));
        }
        if (pGPPublicKey.subSigs != null) {
            this.subSigs = new ArrayList(pGPPublicKey.subSigs.size());
            this.subSigs.addAll(pGPPublicKey.subSigs);
        }
        this.keyStrength = pGPPublicKey.keyStrength;
        this.keyIdentifier = pGPPublicKey.keyIdentifier;
    }

    PGPPublicKey(PGPPublicKey pGPPublicKey, TrustPacket trustPacket, List<PGPSignature> list) {
        this.keySigs = new ArrayList();
        this.ids = new ArrayList();
        this.idTrusts = new ArrayList();
        this.idSigs = new ArrayList();
        this.subSigs = null;
        this.publicPk = pGPPublicKey.publicPk;
        this.trustPk = trustPacket;
        this.subSigs = list;
        this.keyStrength = pGPPublicKey.keyStrength;
        this.keyIdentifier = pGPPublicKey.keyIdentifier;
    }

    PGPPublicKey(PGPPublicKey pGPPublicKey, TrustPacket trustPacket, List<PGPSignature> list, List<UserDataPacket> list2, List<TrustPacket> list3, List<List<PGPSignature>> list4) throws PGPException {
        this.keySigs = new ArrayList();
        this.ids = new ArrayList();
        this.idTrusts = new ArrayList();
        this.idSigs = new ArrayList();
        this.subSigs = null;
        this.publicPk = pGPPublicKey.publicPk;
        this.keyStrength = pGPPublicKey.keyStrength;
        this.keyIdentifier = pGPPublicKey.keyIdentifier;
        this.trustPk = trustPacket;
        this.keySigs = list;
        this.ids = list2;
        this.idTrusts = list3;
        this.idSigs = list4;
    }

    private static PGPPublicKey addCert(PGPPublicKey pGPPublicKey, UserDataPacket userDataPacket, PGPSignature pGPSignature) {
        PGPPublicKey pGPPublicKey2 = new PGPPublicKey(pGPPublicKey);
        List<PGPSignature> list = null;
        for (int i = 0; i != pGPPublicKey2.ids.size(); i++) {
            if (userDataPacket.equals(pGPPublicKey2.ids.get(i))) {
                list = pGPPublicKey2.idSigs.get(i);
            }
        }
        if (list != null) {
            list.add(pGPSignature);
        } else {
            ArrayList arrayList = new ArrayList();
            arrayList.add(pGPSignature);
            pGPPublicKey2.ids.add(userDataPacket);
            pGPPublicKey2.idTrusts.add(null);
            pGPPublicKey2.idSigs.add(arrayList);
        }
        return pGPPublicKey2;
    }

    public static PGPPublicKey addCertification(PGPPublicKey pGPPublicKey, String str, PGPSignature pGPSignature) {
        return addCert(pGPPublicKey, new UserIDPacket(str), pGPSignature);
    }

    public static PGPPublicKey addCertification(PGPPublicKey pGPPublicKey, PGPSignature pGPSignature) {
        if (pGPPublicKey.isMasterKey()) {
            if (pGPSignature.getSignatureType() == 40) {
                throw new IllegalArgumentException("signature type incorrect for master key revocation.");
            }
        } else if (pGPSignature.getSignatureType() == 32) {
            throw new IllegalArgumentException("signature type incorrect for sub-key revocation.");
        }
        PGPPublicKey pGPPublicKey2 = new PGPPublicKey(pGPPublicKey);
        (pGPPublicKey2.subSigs != null ? pGPPublicKey2.subSigs : pGPPublicKey2.keySigs).add(pGPSignature);
        return pGPPublicKey2;
    }

    public static PGPPublicKey addCertification(PGPPublicKey pGPPublicKey, PGPUserAttributeSubpacketVector pGPUserAttributeSubpacketVector, PGPSignature pGPSignature) {
        return addCert(pGPPublicKey, pGPUserAttributeSubpacketVector, pGPSignature);
    }

    public static PGPPublicKey addCertification(PGPPublicKey pGPPublicKey, byte[] bArr, PGPSignature pGPSignature) {
        return addCert(pGPPublicKey, new UserIDPacket(bArr), pGPSignature);
    }

    private long getExpirationTimeFromSig(boolean z, int i) {
        Iterator<PGPSignature> signaturesOfType = getSignaturesOfType(i);
        long j = -1;
        long time = -1;
        while (signaturesOfType.hasNext()) {
            PGPSignature next = signaturesOfType.next();
            if (!z || next.getKeyID() == getKeyID()) {
                PGPSignatureSubpacketVector hashedSubPackets = next.getHashedSubPackets();
                if (hashedSubPackets != null && hashedSubPackets.hasSubpacket(9)) {
                    long keyExpirationTime = hashedSubPackets.getKeyExpirationTime();
                    if (next.getKeyID() == getKeyID()) {
                        if (next.getCreationTime().getTime() > time) {
                            time = next.getCreationTime().getTime();
                            j = keyExpirationTime;
                        }
                    } else if (keyExpirationTime == 0 || keyExpirationTime > j) {
                        j = keyExpirationTime;
                    }
                }
            }
        }
        return j;
    }

    private Iterator<PGPSignature> getSignaturesForID(UserIDPacket userIDPacket) {
        ArrayList arrayList = new ArrayList();
        boolean z = false;
        for (int i = 0; i != this.ids.size(); i++) {
            if (userIDPacket.equals(this.ids.get(i))) {
                arrayList.addAll(this.idSigs.get(i));
                z = true;
            }
        }
        if (z) {
            return arrayList.iterator();
        }
        return null;
    }

    /* JADX WARN: Code duplicated, block: B:4:0x0022  */
    private void init(KeyFingerPrintCalculator keyFingerPrintCalculator) throws PGPException {
        int length;
        BigInteger p;
        BCPGKey key = this.publicPk.getKey();
        byte[] bArrCalculateFingerprint = keyFingerPrintCalculator.calculateFingerprint(this.publicPk);
        this.keyIdentifier = new KeyIdentifier(bArrCalculateFingerprint, PublicKeyPacket.getKeyID(this.publicPk, bArrCalculateFingerprint));
        if (this.publicPk.getVersion() <= 3) {
            p = ((RSAPublicBCPGKey) key).getModulus();
            length = p.bitLength();
        } else {
            if (this.publicPk.getVersion() < 4) {
                return;
            }
            if (key instanceof RSAPublicBCPGKey) {
                p = ((RSAPublicBCPGKey) key).getModulus();
            } else if (key instanceof DSAPublicBCPGKey) {
                p = ((DSAPublicBCPGKey) key).getP();
            } else if (key instanceof ElGamalPublicBCPGKey) {
                p = ((ElGamalPublicBCPGKey) key).getP();
            } else if (key instanceof ECPublicBCPGKey) {
                ASN1ObjectIdentifier curveOID = ((ECPublicBCPGKey) key).getCurveOID();
                if (curveOID.equals((ASN1Primitive) GNUObjectIdentifiers.Ed25519) || curveOID.equals((ASN1Primitive) CryptlibObjectIdentifiers.curvey25519)) {
                    length = 256;
                } else if (curveOID.equals((ASN1Primitive) EdECObjectIdentifiers.id_X448)) {
                    length = 448;
                } else if (curveOID.equals((ASN1Primitive) EdECObjectIdentifiers.id_Ed448)) {
                    length = 456;
                } else {
                    X9ECParametersHolder byOIDLazy = ECNamedCurveTable.getByOIDLazy(curveOID);
                    length = byOIDLazy != null ? byOIDLazy.getCurve().getFieldSize() : -1;
                }
            } else if (!(key instanceof OctetArrayBCPGKey)) {
                return;
            } else {
                length = key.getEncoded().length * 8;
            }
            length = p.bitLength();
        }
        this.keyStrength = length;
    }

    public static PGPPublicKey join(PGPPublicKey pGPPublicKey, PGPPublicKey pGPPublicKey2, boolean z, boolean z2) throws PGPException {
        TrustPacket trustPacket;
        if (pGPPublicKey.getKeyID() != pGPPublicKey2.getKeyID()) {
            throw new IllegalArgumentException("Key-ID mismatch.");
        }
        TrustPacket trustPacket2 = pGPPublicKey.trustPk;
        ArrayList arrayList = new ArrayList(pGPPublicKey.keySigs);
        ArrayList arrayList2 = new ArrayList(pGPPublicKey.ids);
        ArrayList arrayList3 = new ArrayList(pGPPublicKey.idTrusts);
        ArrayList arrayList4 = new ArrayList(pGPPublicKey.idSigs);
        ArrayList arrayList5 = pGPPublicKey.subSigs == null ? null : new ArrayList(pGPPublicKey.subSigs);
        if (z && pGPPublicKey2.trustPk != null) {
            trustPacket2 = pGPPublicKey2.trustPk;
        }
        int i = 0;
        joinPgpSignatureList(pGPPublicKey2.keySigs, arrayList, false, true);
        int i2 = 0;
        while (i2 < pGPPublicKey2.ids.size()) {
            UserDataPacket userDataPacket = pGPPublicKey2.ids.get(i2);
            ArrayList arrayList6 = new ArrayList(pGPPublicKey2.idSigs.get(i2));
            TrustPacket trustPacket3 = pGPPublicKey2.idTrusts.get(i2);
            int i3 = i;
            while (true) {
                if (i3 >= arrayList2.size()) {
                    i3 = -1;
                    break;
                }
                if (((UserDataPacket) arrayList2.get(i3)).equals(userDataPacket)) {
                    break;
                }
                i3++;
            }
            if (i3 == -1) {
                arrayList2.add(userDataPacket);
                arrayList4.add(arrayList6);
                if (!z) {
                    trustPacket3 = null;
                }
                arrayList3.add(trustPacket3);
            } else {
                if (z && trustPacket3 != null && ((trustPacket = (TrustPacket) arrayList3.get(i3)) == null || Arrays.areEqual(trustPacket3.getLevelAndTrustAmount(), trustPacket.getLevelAndTrustAmount()))) {
                    arrayList3.set(i3, trustPacket3);
                }
                joinPgpSignatureList(arrayList6, (List) arrayList4.get(i3), false, true);
            }
            i2++;
            i = 0;
        }
        if (pGPPublicKey2.subSigs != null) {
            if (arrayList5 == null && z2) {
                arrayList5 = new ArrayList(pGPPublicKey2.subSigs);
            } else {
                joinPgpSignatureList(pGPPublicKey2.subSigs, arrayList5, false, arrayList5 != null);
            }
        }
        PGPPublicKey pGPPublicKey3 = new PGPPublicKey(pGPPublicKey, trustPacket2, arrayList, arrayList2, arrayList3, arrayList4);
        pGPPublicKey3.subSigs = arrayList5;
        return pGPPublicKey3;
    }

    private static void joinPgpSignatureList(List<PGPSignature> list, List<PGPSignature> list2, boolean z, boolean z2) throws PGPException {
        for (PGPSignature pGPSignature : list) {
            boolean z3 = false;
            for (int i = 0; z2 && i < list2.size(); i++) {
                PGPSignature pGPSignature2 = list2.get(i);
                if (pGPSignature2.getVersion() == pGPSignature.getVersion() && PGPSignature.isSignatureEncodingEqual(pGPSignature2, pGPSignature)) {
                    list2.set(i, PGPSignature.join(pGPSignature2, pGPSignature));
                    z3 = true;
                    break;
                }
            }
            if (z3 && z) {
                return;
            }
            if (!z3 && z2) {
                list2.add(pGPSignature);
            }
        }
    }

    private static PGPPublicKey removeCert(PGPPublicKey pGPPublicKey, UserDataPacket userDataPacket) {
        PGPPublicKey pGPPublicKey2 = new PGPPublicKey(pGPPublicKey);
        boolean z = false;
        for (int size = pGPPublicKey2.ids.size() - 1; size >= 0; size--) {
            if (userDataPacket.equals(pGPPublicKey2.ids.get(size))) {
                pGPPublicKey2.ids.remove(size);
                pGPPublicKey2.idTrusts.remove(size);
                pGPPublicKey2.idSigs.remove(size);
                z = true;
            }
        }
        if (z) {
            return pGPPublicKey2;
        }
        return null;
    }

    private static PGPPublicKey removeCert(PGPPublicKey pGPPublicKey, UserDataPacket userDataPacket, PGPSignature pGPSignature) {
        PGPPublicKey pGPPublicKey2 = new PGPPublicKey(pGPPublicKey);
        boolean zRemove = false;
        for (int i = 0; i < pGPPublicKey2.ids.size(); i++) {
            if (userDataPacket.equals(pGPPublicKey2.ids.get(i))) {
                zRemove |= pGPPublicKey2.idSigs.get(i).remove(pGPSignature);
            }
        }
        if (zRemove) {
            return pGPPublicKey2;
        }
        return null;
    }

    public static PGPPublicKey removeCertification(PGPPublicKey pGPPublicKey, String str) {
        return removeCert(pGPPublicKey, new UserIDPacket(str));
    }

    public static PGPPublicKey removeCertification(PGPPublicKey pGPPublicKey, String str, PGPSignature pGPSignature) {
        return removeCert(pGPPublicKey, new UserIDPacket(str), pGPSignature);
    }

    public static PGPPublicKey removeCertification(PGPPublicKey pGPPublicKey, PGPSignature pGPSignature) {
        PGPPublicKey pGPPublicKey2 = new PGPPublicKey(pGPPublicKey);
        boolean zRemove = (pGPPublicKey2.subSigs != null ? pGPPublicKey2.subSigs : pGPPublicKey2.keySigs).remove(pGPSignature);
        Iterator<List<PGPSignature>> it = pGPPublicKey2.idSigs.iterator();
        while (it.hasNext()) {
            zRemove |= it.next().remove(pGPSignature);
        }
        if (zRemove) {
            return pGPPublicKey2;
        }
        return null;
    }

    public static PGPPublicKey removeCertification(PGPPublicKey pGPPublicKey, PGPUserAttributeSubpacketVector pGPUserAttributeSubpacketVector) {
        return removeCert(pGPPublicKey, pGPUserAttributeSubpacketVector);
    }

    public static PGPPublicKey removeCertification(PGPPublicKey pGPPublicKey, PGPUserAttributeSubpacketVector pGPUserAttributeSubpacketVector, PGPSignature pGPSignature) {
        return removeCert(pGPPublicKey, pGPUserAttributeSubpacketVector, pGPSignature);
    }

    public static PGPPublicKey removeCertification(PGPPublicKey pGPPublicKey, byte[] bArr) {
        return removeCert(pGPPublicKey, new UserIDPacket(bArr));
    }

    public static PGPPublicKey removeCertification(PGPPublicKey pGPPublicKey, byte[] bArr, PGPSignature pGPSignature) {
        return removeCert(pGPPublicKey, new UserIDPacket(bArr), pGPSignature);
    }

    public void encode(OutputStream outputStream) throws IOException {
        encode(outputStream, false);
    }

    public void encode(OutputStream outputStream, boolean z) throws IOException {
        BCPGOutputStream bCPGOutputStreamWrap = BCPGOutputStream.wrap(outputStream);
        bCPGOutputStreamWrap.writePacket(this.publicPk);
        if (!z && this.trustPk != null) {
            bCPGOutputStreamWrap.writePacket(this.trustPk);
        }
        if (this.subSigs != null) {
            Util.encodePGPSignatures(bCPGOutputStreamWrap, this.subSigs, z);
            return;
        }
        Util.encodePGPSignatures(bCPGOutputStreamWrap, this.keySigs, false);
        for (int i = 0; i != this.ids.size(); i++) {
            boolean z2 = this.ids.get(i) instanceof UserIDPacket;
            List<UserDataPacket> list = this.ids;
            if (z2) {
                bCPGOutputStreamWrap.writePacket((UserIDPacket) list.get(i));
            } else {
                bCPGOutputStreamWrap.writePacket(new UserAttributePacket(((PGPUserAttributeSubpacketVector) list.get(i)).toSubpacketArray()));
            }
            if (!z && this.idTrusts.get(i) != null) {
                bCPGOutputStreamWrap.writePacket(this.idTrusts.get(i));
            }
            Util.encodePGPSignatures(bCPGOutputStreamWrap, this.idSigs.get(i), z);
        }
    }

    public int getAlgorithm() {
        return this.publicPk.getAlgorithm();
    }

    public int getBitStrength() {
        return this.keyStrength;
    }

    public Date getCreationTime() {
        return this.publicPk.getTime();
    }

    public byte[] getEncoded() throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        encode(byteArrayOutputStream, false);
        return byteArrayOutputStream.toByteArray();
    }

    public byte[] getEncoded(boolean z) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        encode(byteArrayOutputStream, z);
        return byteArrayOutputStream.toByteArray();
    }

    public byte[] getFingerprint() {
        return this.keyIdentifier.getFingerprint();
    }

    public long getKeyID() {
        return this.keyIdentifier.getKeyId();
    }

    public KeyIdentifier getKeyIdentifier() {
        return this.keyIdentifier;
    }

    public Iterator<PGPSignature> getKeySignatures() {
        return (this.subSigs == null ? new ArrayList(this.keySigs) : this.subSigs).iterator();
    }

    public PublicKeyPacket getPublicKeyPacket() {
        return this.publicPk;
    }

    public Iterator<byte[]> getRawUserIDs() {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i != this.ids.size(); i++) {
            if (this.ids.get(i) instanceof UserIDPacket) {
                arrayList.add(((UserIDPacket) this.ids.get(i)).getRawID());
            }
        }
        return arrayList.iterator();
    }

    public Iterator<PGPSignature> getSignatures() {
        if (this.subSigs != null) {
            return this.subSigs.iterator();
        }
        ArrayList arrayList = new ArrayList(this.keySigs);
        for (int i = 0; i != this.idSigs.size(); i++) {
            arrayList.addAll(this.idSigs.get(i));
        }
        return arrayList.iterator();
    }

    public Iterator<PGPSignature> getSignaturesForID(String str) {
        return getSignaturesForID(new UserIDPacket(str));
    }

    public Iterator<PGPSignature> getSignaturesForID(byte[] bArr) {
        return getSignaturesForID(new UserIDPacket(bArr));
    }

    public Iterator<PGPSignature> getSignaturesForKey(KeyIdentifier keyIdentifier) {
        ArrayList arrayList = new ArrayList();
        Iterator<PGPSignature> signatures = getSignatures();
        while (signatures.hasNext()) {
            PGPSignature next = signatures.next();
            if (keyIdentifier.isPresentIn(next.getKeyIdentifiers())) {
                arrayList.add(next);
            }
        }
        return arrayList.iterator();
    }

    public Iterator<PGPSignature> getSignaturesForKeyID(long j) {
        ArrayList arrayList = new ArrayList();
        Iterator<PGPSignature> signatures = getSignatures();
        while (signatures.hasNext()) {
            PGPSignature next = signatures.next();
            if (next.getKeyID() == j) {
                arrayList.add(next);
            }
        }
        return arrayList.iterator();
    }

    public Iterator<PGPSignature> getSignaturesForUserAttribute(PGPUserAttributeSubpacketVector pGPUserAttributeSubpacketVector) {
        ArrayList arrayList = new ArrayList();
        boolean z = false;
        for (int i = 0; i != this.ids.size(); i++) {
            if (pGPUserAttributeSubpacketVector.equals(this.ids.get(i))) {
                arrayList.addAll(this.idSigs.get(i));
                z = true;
            }
        }
        if (z) {
            return arrayList.iterator();
        }
        return null;
    }

    public Iterator<PGPSignature> getSignaturesOfType(int i) {
        ArrayList arrayList = new ArrayList();
        Iterator<PGPSignature> signatures = getSignatures();
        while (signatures.hasNext()) {
            PGPSignature next = signatures.next();
            if (next.getSignatureType() == i) {
                arrayList.add(next);
            }
        }
        return arrayList.iterator();
    }

    public byte[] getTrustData() {
        if (this.trustPk == null) {
            return null;
        }
        return Arrays.clone(this.trustPk.getLevelAndTrustAmount());
    }

    public Iterator<PGPUserAttributeSubpacketVector> getUserAttributes() {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i != this.ids.size(); i++) {
            if (this.ids.get(i) instanceof PGPUserAttributeSubpacketVector) {
                arrayList.add((PGPUserAttributeSubpacketVector) this.ids.get(i));
            }
        }
        return arrayList.iterator();
    }

    public Iterator<String> getUserIDs() {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i != this.ids.size(); i++) {
            if (this.ids.get(i) instanceof UserIDPacket) {
                try {
                    arrayList.add(((UserIDPacket) this.ids.get(i)).getID());
                } catch (IllegalArgumentException e) {
                }
            }
        }
        return arrayList.iterator();
    }

    public int getValidDays() {
        if (this.publicPk.getVersion() <= 3) {
            return this.publicPk.getValidDays();
        }
        long validSeconds = getValidSeconds() % 86400;
        int validSeconds2 = (int) (getValidSeconds() / 86400);
        if (validSeconds <= 0 || validSeconds2 != 0) {
            return validSeconds2;
        }
        return 1;
    }

    public long getValidSeconds() {
        if (this.publicPk.getVersion() <= 3) {
            return ((long) this.publicPk.getValidDays()) * 24 * 60 * 60;
        }
        if (isMasterKey()) {
            for (int i = 0; i != MASTER_KEY_CERTIFICATION_TYPES.length; i++) {
                long expirationTimeFromSig = getExpirationTimeFromSig(true, MASTER_KEY_CERTIFICATION_TYPES[i]);
                if (expirationTimeFromSig >= 0) {
                    return expirationTimeFromSig;
                }
            }
        } else {
            long expirationTimeFromSig2 = getExpirationTimeFromSig(false, 24);
            if (expirationTimeFromSig2 >= 0) {
                return expirationTimeFromSig2;
            }
            long expirationTimeFromSig3 = getExpirationTimeFromSig(false, 31);
            if (expirationTimeFromSig3 >= 0) {
                return expirationTimeFromSig3;
            }
        }
        return 0L;
    }

    public int getVersion() {
        return this.publicPk.getVersion();
    }

    public boolean hasFingerprint(byte[] bArr) {
        return this.keyIdentifier.hasFingerprint(bArr);
    }

    public boolean hasRevocation() {
        boolean z = false;
        if (isMasterKey()) {
            int i = 0;
            while (!z && i < this.keySigs.size()) {
                int i2 = i + 1;
                if (this.keySigs.get(i).getSignatureType() == 32) {
                    z = true;
                }
                i = i2;
            }
        } else {
            int i3 = 0;
            while (!z && i3 < this.subSigs.size()) {
                int i4 = i3 + 1;
                if (this.subSigs.get(i3).getSignatureType() == 40) {
                    z = true;
                }
                i3 = i4;
            }
        }
        return z;
    }

    public boolean isEncryptionKey() {
        int algorithm = this.publicPk.getAlgorithm();
        return algorithm == 1 || algorithm == 2 || algorithm == 16 || algorithm == 20 || algorithm == 21 || algorithm == 18 || algorithm == 26 || algorithm == 25;
    }

    public boolean isMasterKey() {
        return !(this.publicPk instanceof PublicSubkeyPacket) && (!isEncryptionKey() || this.publicPk.getAlgorithm() == 1);
    }

    public boolean isRevoked() {
        return hasRevocation();
    }
}
