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);
}
Aggregations