From ea9b0d68fb15585c0a4c25e1f38c90c0e3742e2b Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 12 Jun 2023 14:37:33 +0200 Subject: [PATCH] SOP: Test profile support of encrypt subcommand --- .../sop/EncryptDecryptRoundTripTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pgpainless-sop/src/test/java/org/pgpainless/sop/EncryptDecryptRoundTripTest.java b/pgpainless-sop/src/test/java/org/pgpainless/sop/EncryptDecryptRoundTripTest.java index f51b711d..30305edd 100644 --- a/pgpainless-sop/src/test/java/org/pgpainless/sop/EncryptDecryptRoundTripTest.java +++ b/pgpainless-sop/src/test/java/org/pgpainless/sop/EncryptDecryptRoundTripTest.java @@ -546,4 +546,32 @@ public class EncryptDecryptRoundTripTest { .toByteArrayAndResult() ); } + + @Test + public void encryptWithUnsupportedProfileFails() { + assertThrows(SOPGPException.UnsupportedProfile.class, () -> sop + .encrypt() + .profile("Unknown")); + } + + @Test + public void encryptWithSupportedProfileTest() throws IOException { + byte[] encrypted = sop.encrypt() + .profile("rfc4880") + .withCert(bobCert) + .plaintext(message) + .getBytes(); + + ByteArrayAndResult bytesAndResult = sop.decrypt() + .withKey(bobKey) + .ciphertext(encrypted) + .toByteArrayAndResult(); + + ByteArrayOutputStream decrypted = new ByteArrayOutputStream(); + Streams.pipeAll(bytesAndResult.getInputStream(), decrypted); + assertArrayEquals(message, decrypted.toByteArray()); + + DecryptionResult result = bytesAndResult.getResult(); + assertTrue(result.getSessionKey().isPresent()); + } }