Search in sources :

Example 1 with UnsignedPublicKeySelfCertification

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));
}
Also used : SignatureAttributesWithoutHashPrefix(co.krypt.krypton.pgp.packet.SignatureAttributesWithoutHashPrefix) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CertifiedPublicKey(co.krypt.krypton.pgp.publickey.CertifiedPublicKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) UnsignedPublicKeySelfCertification(co.krypt.krypton.pgp.publickey.UnsignedPublicKeySelfCertification) Test(org.junit.Test)

Aggregations

SignatureAttributesWithoutHashPrefix (co.krypt.krypton.pgp.packet.SignatureAttributesWithoutHashPrefix)1 CertifiedPublicKey (co.krypt.krypton.pgp.publickey.CertifiedPublicKey)1 UnsignedPublicKeySelfCertification (co.krypt.krypton.pgp.publickey.UnsignedPublicKeySelfCertification)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 Test (org.junit.Test)1