Search in sources :

Example 1 with UserIDPacket

use of co.krypt.krypton.pgp.packet.UserIDPacket in project krypton-android by kryptco.

the class CertifiedPublicKey method parse.

public static CertifiedPublicKey parse(DataInputStream in) throws InvalidPacketTagException, UnsupportedOldPacketLengthTypeException, UnsupportedNewFormatException, UnsupportedPublicKeyAlgorithmException, UnsupportedPublicKeyVersionException, InvalidEd25519PublicKeyFormatException, IOException, InvalidUTF8Exception, DuplicateSubpacketException, NoSuchAlgorithmException, UnsupportedHashAlgorithmException, InvalidSubpacketLengthException, UnsupportedCriticalSubpacketTypeException, UnsupportedSignatureVersionException {
    PublicKeyPacket publicKeyPacket = null;
    boolean lastPacketUserIDOrSignature = false;
    List<Pair<UserIDPacket, List<SignedSignatureAttributes>>> identities = new LinkedList<>();
    while (true) {
        try {
            PacketHeader header = PacketHeader.parse(in);
            Log.d("PGP", "found packet with type " + header.tag.packetType.toString());
            switch(header.tag.packetType) {
                case SIGNATURE:
                    SignedSignatureAttributes signaturePacket = SignedSignatureAttributes.parse(header, in);
                    if (lastPacketUserIDOrSignature && identities.size() > 0) {
                        identities.get(identities.size() - 1).second.add(signaturePacket);
                    }
                    break;
                case PUBLIC_KEY:
                    if (publicKeyPacket != null) {
                        // only accept first public key packet
                        in.skip(header.length.bodyLength);
                        continue;
                    }
                    publicKeyPacket = PublicKeyPacket.parse(header, in);
                    break;
                case USER_ID:
                    identities.add(new Pair<UserIDPacket, List<SignedSignatureAttributes>>(UserIDPacket.parse(header, in), new LinkedList<SignedSignatureAttributes>()));
                    break;
                default:
                    in.skip(header.length.bodyLength);
                    break;
            }
            lastPacketUserIDOrSignature = header.tag.packetType == PacketType.USER_ID || header.tag.packetType == PacketType.SIGNATURE;
        } catch (EOFException e) {
            break;
        }
    }
    return new CertifiedPublicKey(publicKeyPacket, identities);
}
Also used : SignedSignatureAttributes(co.krypt.krypton.pgp.packet.SignedSignatureAttributes) EOFException(java.io.EOFException) PacketHeader(co.krypt.krypton.pgp.packet.PacketHeader) List(java.util.List) LinkedList(java.util.LinkedList) UserIDPacket(co.krypt.krypton.pgp.packet.UserIDPacket) LinkedList(java.util.LinkedList) Pair(android.support.v4.util.Pair)

Aggregations

Pair (android.support.v4.util.Pair)1 PacketHeader (co.krypt.krypton.pgp.packet.PacketHeader)1 SignedSignatureAttributes (co.krypt.krypton.pgp.packet.SignedSignatureAttributes)1 UserIDPacket (co.krypt.krypton.pgp.packet.UserIDPacket)1 EOFException (java.io.EOFException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1