internal static PgpPublicKey ReadSubkey(BcpgInputStream bcpgInput)
    {
        PublicKeyPacket publicPk = (PublicKeyPacket)bcpgInput.ReadPacket();
        TrustPacket     trustPk  = PgpKeyRing.ReadOptionalTrustPacket(bcpgInput);
        IList           sigs     = PgpKeyRing.ReadSignaturesAndTrust(bcpgInput);

        return(new PgpPublicKey(publicPk, trustPk, sigs));
    }
    public PgpSecretKeyRing(Stream inputStream)
    {
        keys         = Platform.CreateArrayList();
        extraPubKeys = Platform.CreateArrayList();
        BcpgInputStream bcpgInputStream = BcpgInputStream.Wrap(inputStream);
        PacketTag       packetTag       = bcpgInputStream.NextPacketTag();

        if (packetTag != PacketTag.SecretKey && packetTag != PacketTag.SecretSubkey)
        {
            int num = (int)packetTag;
            throw new IOException("secret key ring doesn't start with secret key tag: tag 0x" + num.ToString("X"));
        }
        SecretKeyPacket secretKeyPacket = (SecretKeyPacket)bcpgInputStream.ReadPacket();

        while (bcpgInputStream.NextPacketTag() == PacketTag.Experimental2)
        {
            bcpgInputStream.ReadPacket();
        }
        TrustPacket trustPk = PgpKeyRing.ReadOptionalTrustPacket(bcpgInputStream);
        IList       keySigs = PgpKeyRing.ReadSignaturesAndTrust(bcpgInputStream);

        PgpKeyRing.ReadUserIDs(bcpgInputStream, out IList ids, out IList idTrusts, out IList idSigs);
        keys.Add(new PgpSecretKey(secretKeyPacket, new PgpPublicKey(secretKeyPacket.PublicKeyPacket, trustPk, keySigs, ids, idTrusts, idSigs)));
        while (bcpgInputStream.NextPacketTag() == PacketTag.SecretSubkey || bcpgInputStream.NextPacketTag() == PacketTag.PublicSubkey)
        {
            if (bcpgInputStream.NextPacketTag() == PacketTag.SecretSubkey)
            {
                SecretSubkeyPacket secretSubkeyPacket = (SecretSubkeyPacket)bcpgInputStream.ReadPacket();
                while (bcpgInputStream.NextPacketTag() == PacketTag.Experimental2)
                {
                    bcpgInputStream.ReadPacket();
                }
                TrustPacket trustPk2 = PgpKeyRing.ReadOptionalTrustPacket(bcpgInputStream);
                IList       sigs     = PgpKeyRing.ReadSignaturesAndTrust(bcpgInputStream);
                keys.Add(new PgpSecretKey(secretSubkeyPacket, new PgpPublicKey(secretSubkeyPacket.PublicKeyPacket, trustPk2, sigs)));
            }
            else
            {
                PublicSubkeyPacket publicPk = (PublicSubkeyPacket)bcpgInputStream.ReadPacket();
                TrustPacket        trustPk3 = PgpKeyRing.ReadOptionalTrustPacket(bcpgInputStream);
                IList sigs2 = PgpKeyRing.ReadSignaturesAndTrust(bcpgInputStream);
                extraPubKeys.Add(new PgpPublicKey(publicPk, trustPk3, sigs2));
            }
        }
    }
    public PgpPublicKeyRing(Stream inputStream)
    {
        keys = Platform.CreateArrayList();
        BcpgInputStream bcpgInputStream = BcpgInputStream.Wrap(inputStream);
        PacketTag       packetTag       = bcpgInputStream.NextPacketTag();

        if (packetTag != PacketTag.PublicKey && packetTag != PacketTag.PublicSubkey)
        {
            int num = (int)packetTag;
            throw new IOException("public key ring doesn't start with public key tag: tag 0x" + num.ToString("X"));
        }
        PublicKeyPacket publicPk = (PublicKeyPacket)bcpgInputStream.ReadPacket();
        TrustPacket     trustPk  = PgpKeyRing.ReadOptionalTrustPacket(bcpgInputStream);
        IList           keySigs  = PgpKeyRing.ReadSignaturesAndTrust(bcpgInputStream);

        PgpKeyRing.ReadUserIDs(bcpgInputStream, out IList ids, out IList idTrusts, out IList idSigs);
        keys.Add(new PgpPublicKey(publicPk, trustPk, keySigs, ids, idTrusts, idSigs));
        while (bcpgInputStream.NextPacketTag() == PacketTag.PublicSubkey)
        {
            keys.Add(ReadSubkey(bcpgInputStream));
        }
    }