mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 19:08:00 +01:00
Add OnePassSignature verification test
This commit is contained in:
parent
7de04c2949
commit
01f81fabaa
1 changed files with 32 additions and 0 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue