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
1 changed files with 32 additions and 0 deletions

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