use of co.krypt.krypton.pgp.packet.PacketHeader 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);
}
use of co.krypt.krypton.pgp.packet.PacketHeader in project krypton-android by kryptco.
the class PGPPacketTest method invalidUserIDPacket_throwsIO.
@Test(expected = InvalidUTF8Exception.class)
public void invalidUserIDPacket_throwsIO() throws Exception {
PacketHeader header = new PacketHeader(PacketTag.parse((byte) (PacketTag.LEADING_ONE | OldPacketLengthType.ONE_OCTET.getValue() | (PacketType.USER_ID.getValue() << 2))), 2);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(new byte[] { (byte) 0xc3, 0x28 }));
UserIDPacket.parse(header, in);
}
Aggregations