package org.bouncycastle.openpgp;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.KeyIdentifier;
import org.bouncycastle.bcpg.Packet;
import org.bouncycastle.bcpg.PacketFormat;
import org.bouncycastle.bcpg.SignaturePacket;
import org.bouncycastle.bcpg.TrustPacket;
import org.bouncycastle.bcpg.UnsupportedPacketVersionException;
import org.bouncycastle.bcpg.UserAttributePacket;
import org.bouncycastle.bcpg.UserDataPacket;
import org.bouncycastle.bcpg.UserIDPacket;

/* JADX INFO: loaded from: classes.dex */
public abstract class PGPKeyRing {
    private static final Logger LOG = Logger.getLogger(PGPKeyRing.class.getName());

    PGPKeyRing() {
    }

    private static boolean isUserTag(int i) {
        switch (i) {
            case 13:
            case 17:
                return true;
            default:
                return false;
        }
    }

    static TrustPacket readOptionalTrustPacket(BCPGInputStream bCPGInputStream) throws IOException {
        if (bCPGInputStream.skipMarkerAndPaddingPackets() == 12) {
            return (TrustPacket) bCPGInputStream.readPacket();
        }
        return null;
    }

    static List<PGPSignature> readSignaturesAndTrust(BCPGInputStream bCPGInputStream) throws IOException {
        ArrayList arrayList = new ArrayList();
        while (bCPGInputStream.skipMarkerAndPaddingPackets() == 2) {
            try {
                arrayList.add(new PGPSignature((SignaturePacket) bCPGInputStream.readPacket(), readOptionalTrustPacket(bCPGInputStream)));
            } catch (UnsupportedPacketVersionException e) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("skipping unknown signature: " + e.getMessage());
                }
            }
        }
        return arrayList;
    }

    static void readUserIDs(BCPGInputStream bCPGInputStream, List<UserDataPacket> list, List<TrustPacket> list2, List<List<PGPSignature>> list3) throws IOException {
        while (isUserTag(bCPGInputStream.skipMarkerAndPaddingPackets())) {
            Packet packet = bCPGInputStream.readPacket();
            if (packet instanceof UserIDPacket) {
                list.add((UserIDPacket) packet);
            } else {
                list.add(new PGPUserAttributeSubpacketVector(((UserAttributePacket) packet).getSubpackets()));
            }
            list2.add(readOptionalTrustPacket(bCPGInputStream));
            list3.add(readSignaturesAndTrust(bCPGInputStream));
        }
    }

    public abstract void encode(OutputStream outputStream) throws IOException;

    public abstract byte[] getEncoded() throws IOException;

    public abstract byte[] getEncoded(PacketFormat packetFormat) throws IOException;

    public KeyIdentifier getKeyIdentifier() {
        return getPublicKey().getKeyIdentifier();
    }

    public abstract Iterator<PGPPublicKey> getKeysWithSignaturesBy(long j);

    public abstract Iterator<PGPPublicKey> getKeysWithSignaturesBy(KeyIdentifier keyIdentifier);

    public abstract PGPPublicKey getPublicKey();

    public abstract PGPPublicKey getPublicKey(long j);

    public abstract PGPPublicKey getPublicKey(KeyIdentifier keyIdentifier);

    public abstract PGPPublicKey getPublicKey(byte[] bArr);

    public abstract Iterator<PGPPublicKey> getPublicKeys();

    public abstract Iterator<PGPPublicKey> getPublicKeys(KeyIdentifier keyIdentifier);

    public abstract int size();
}
