use of co.krypt.krypton.pgp.publickey.UnsignedPublicKeySelfCertification in project krypton-android by kryptco.
the class PGPSignatureTest method signedPublicKeyHashPrefixAndReserializedBytes_match.
@Test
public void signedPublicKeyHashPrefixAndReserializedBytes_match() throws Exception {
byte[] signedKeyData = AsciiArmor.parse(testPubKey2).data;
CertifiedPublicKey pk = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(signedKeyData)));
SignatureAttributesWithoutHashPrefix att = pk.identities.get(0).second.get(0).attributes.attributes;
UnsignedPublicKeySelfCertification certification = new UnsignedPublicKeySelfCertification(pk.publicKeyPacket, pk.identities.get(0).first.userID, att.getHashAlgorithm(), att.hashedSubpackets.created.created, // this pubkey has no flags
null);
Assert.assertTrue(SignableUtils.hashPrefix(att.hashAlgorithm, certification) == pk.identities.get(0).second.get(0).attributes.hashPrefix);
ByteArrayOutputStream reserialized = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(reserialized);
pk.publicKeyPacket.serialize(out);
pk.identities.get(0).first.serialize(out);
pk.identities.get(0).second.get(0).serialize(out);
out.close();
Assert.assertTrue(Arrays.equals(reserialized.toByteArray(), signedKeyData));
}
Aggregations