1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 06:12:06 +01:00

Add OnePassSignature verification test

This commit is contained in:
Paul Schaub 2020-08-30 13:16:47 +02:00
parent 7de04c2949
commit 01f81fabaa
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -227,4 +227,36 @@ public class EncryptDecryptTest {
metadata = verifier.getResult();
assertFalse(metadata.getVerifiedSignatures().isEmpty());
}
@Test
public void testOnePassSignatureCreationAndVerification() throws IOException, PGPException {
PGPKeyRing signingKeys = new PGPKeyRing(TestKeys.getJulietPublicKeyRing(), TestKeys.getJulietSecretKeyRing());
SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector();
byte[] data = testMessage.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
ByteArrayOutputStream signOut = new ByteArrayOutputStream();
EncryptionStream signer = PGPainless.createEncryptor().onOutputStream(signOut)
.doNotEncrypt()
.signWith(keyRingProtector, signingKeys.getSecretKeys())
.asciiArmor();
Streams.pipeAll(inputStream, signer);
signer.close();
// CHECKSTYLE:OFF
System.out.println(signOut.toString());
// CHECKSTYLE:ON
inputStream = new ByteArrayInputStream(signOut.toByteArray());
DecryptionStream verifier = PGPainless.createDecryptor().onInputStream(inputStream)
.doNotDecrypt()
.verifyWith(Collections.singleton(signingKeys.getPublicKeys()))
.ignoreMissingPublicKeys()
.build();
signOut = new ByteArrayOutputStream();
Streams.pipeAll(verifier, signOut);
verifier.close();
OpenPgpMetadata metadata = verifier.getResult();
assertFalse(metadata.getVerifiedSignatures().isEmpty());
}
}