Add VerificationAssert methods, disable tests for unsupported operations

This commit is contained in:
Paul Schaub 2025-07-01 14:38:13 +02:00
parent b3223372c6
commit c651adc0b3
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
17 changed files with 286 additions and 239 deletions

View file

@ -8,9 +8,13 @@ import sop.Verification;
import sop.enums.SignatureMode;
import sop.testsuite.JUtils;
import java.text.ParseException;
import java.util.Date;
import java.util.function.Predicate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public final class VerificationAssert {
@ -57,6 +61,27 @@ public final class VerificationAssert {
return hasDescription(description);
}
public VerificationAssert hasValidJSONOrNull(Verification.JSONParser parser)
throws ParseException {
if (!verification.getJsonOrDescription().isPresent()) {
// missing description
return this;
}
return hasJSON(parser, null);
}
public VerificationAssert hasJSON(Verification.JSONParser parser, Predicate<Verification.JSON> predicate) {
assertTrue(verification.getContainsJson(), "Verification does not appear to contain JSON extension");
Verification.JSON json = verification.getJson(parser);
assertNotNull(verification.getJson(parser), "Verification does not appear to contain valid JSON extension.");
if (predicate != null) {
assertTrue(predicate.test(json), "JSON object does not match predicate.");
}
return this;
}
public VerificationAssert hasMode(SignatureMode mode) {
assertEquals(mode, verification.getSignatureMode().get());
return this;

View file

@ -4,10 +4,13 @@
package sop.testsuite.operation;
import kotlin.jvm.functions.Function0;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Named;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.provider.Arguments;
import sop.SOP;
import sop.exception.SOPGPException;
import sop.testsuite.AbortOnUnsupportedOption;
import sop.testsuite.AbortOnUnsupportedOptionExtension;
import sop.testsuite.SOPInstanceFactory;
@ -18,6 +21,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@ExtendWith(AbortOnUnsupportedOptionExtension.class)
@AbortOnUnsupportedOption
public abstract class AbstractSOPTest {
@ -51,6 +56,17 @@ public abstract class AbstractSOPTest {
}
}
public <T> T assumeSupported(Function0<T> f) {
try {
T t = f.invoke();
assumeTrue(t != null, "Unsupported operation.");
return t;
} catch (SOPGPException.UnsupportedSubcommand e) {
assumeTrue(false, e.getMessage());
return null;
}
}
public static Stream<Arguments> provideBackends() {
return backends.stream();
}

View file

@ -20,7 +20,7 @@ import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
public class ArmorDearmorTest {
public class ArmorDearmorTest extends AbstractSOPTest {
static Stream<Arguments> provideInstances() {
return AbstractSOPTest.provideBackends();
@ -31,13 +31,13 @@ public class ArmorDearmorTest {
public void dearmorArmorAliceKey(SOP sop) throws IOException {
byte[] aliceKey = TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(aliceKey)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -52,13 +52,13 @@ public class ArmorDearmorTest {
public void dearmorArmorAliceCert(SOP sop) throws IOException {
byte[] aliceCert = TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(aliceCert)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -73,13 +73,13 @@ public class ArmorDearmorTest {
public void dearmorArmorBobKey(SOP sop) throws IOException {
byte[] bobKey = TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(bobKey)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -94,13 +94,13 @@ public class ArmorDearmorTest {
public void dearmorArmorBobCert(SOP sop) throws IOException {
byte[] bobCert = TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(bobCert)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -115,13 +115,13 @@ public class ArmorDearmorTest {
public void dearmorArmorCarolKey(SOP sop) throws IOException {
byte[] carolKey = TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(carolKey)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -136,13 +136,13 @@ public class ArmorDearmorTest {
public void dearmorArmorCarolCert(SOP sop) throws IOException {
byte[] carolCert = TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(carolCert)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -163,13 +163,13 @@ public class ArmorDearmorTest {
"CePQFpprprnGEzpE3flQLUc=\n" +
"=ZiFR\n" +
"-----END PGP MESSAGE-----\n").getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(message)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_MESSAGE));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -191,13 +191,13 @@ public class ArmorDearmorTest {
"=GHvQ\n" +
"-----END PGP SIGNATURE-----\n").getBytes(StandardCharsets.UTF_8);
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(signature)
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_SIGNATURE));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(dearmored)
.getBytes();
@ -210,11 +210,11 @@ public class ArmorDearmorTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testDearmoringTwiceIsIdempotent(SOP sop) throws IOException {
byte[] dearmored = sop.dearmor()
byte[] dearmored = assumeSupported(sop::dearmor)
.data(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.getBytes();
byte[] dearmoredAgain = sop.dearmor()
byte[] dearmoredAgain = assumeSupported(sop::dearmor)
.data(dearmored)
.getBytes();
@ -233,7 +233,7 @@ public class ArmorDearmorTest {
"=GHvQ\n" +
"-----END PGP SIGNATURE-----\n").getBytes(StandardCharsets.UTF_8);
byte[] armoredAgain = sop.armor()
byte[] armoredAgain = assumeSupported(sop::armor)
.data(armored)
.getBytes();

View file

@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
public class CertifyValidateUserIdTest {
public class CertifyValidateUserIdTest extends AbstractSOPTest {
static Stream<Arguments> provideInstances() {
return AbstractSOPTest.provideBackends();
@ -27,25 +27,25 @@ public class CertifyValidateUserIdTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void certifyUserId(SOP sop) throws IOException {
byte[] aliceKey = sop.generateKey()
byte[] aliceKey = assumeSupported(sop::generateKey)
.withKeyPassword("sw0rdf1sh")
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] aliceCert = sop.extractCert()
byte[] aliceCert = assumeSupported(sop::extractCert)
.key(aliceKey)
.getBytes();
byte[] bobKey = sop.generateKey()
byte[] bobKey = assumeSupported(sop::generateKey)
.userId("Bob <bob@pgpainless.org>")
.generate()
.getBytes();
byte[] bobCert = sop.extractCert()
byte[] bobCert = assumeSupported(sop::extractCert)
.key(bobKey)
.getBytes();
// Alice has her own user-id self-certified
assertTrue(sop.validateUserId()
assertTrue(assumeSupported(sop::validateUserId)
.authorities(aliceCert)
.userId("Alice <alice@pgpainless.org>")
.subjects(aliceCert),
@ -53,20 +53,20 @@ public class CertifyValidateUserIdTest {
// Alice has not yet certified Bobs user-id
assertThrows(SOPGPException.CertUserIdNoMatch.class, () ->
sop.validateUserId()
assumeSupported(sop::validateUserId)
.authorities(aliceCert)
.userId("Bob <bob@pgpainless.org>")
.subjects(bobCert),
"Alice has not yet certified Bobs user-id");
byte[] bobCertifiedByAlice = sop.certifyUserId()
byte[] bobCertifiedByAlice = assumeSupported(sop::certifyUserId)
.userId("Bob <bob@pgpainless.org>")
.withKeyPassword("sw0rdf1sh")
.keys(aliceKey)
.certs(bobCert)
.getBytes();
assertTrue(sop.validateUserId()
assertTrue(assumeSupported(sop::validateUserId)
.userId("Bob <bob@pgpainless.org>")
.authorities(aliceCert)
.subjects(bobCertifiedByAlice),
@ -76,28 +76,28 @@ public class CertifyValidateUserIdTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void certifyUserIdUnarmored(SOP sop) throws IOException {
byte[] aliceKey = sop.generateKey()
byte[] aliceKey = assumeSupported(sop::generateKey)
.noArmor()
.withKeyPassword("sw0rdf1sh")
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] aliceCert = sop.extractCert()
byte[] aliceCert = assumeSupported(sop::extractCert)
.noArmor()
.key(aliceKey)
.getBytes();
byte[] bobKey = sop.generateKey()
byte[] bobKey = assumeSupported(sop::generateKey)
.noArmor()
.userId("Bob <bob@pgpainless.org>")
.generate()
.getBytes();
byte[] bobCert = sop.extractCert()
byte[] bobCert = assumeSupported(sop::extractCert)
.noArmor()
.key(bobKey)
.getBytes();
byte[] bobCertifiedByAlice = sop.certifyUserId()
byte[] bobCertifiedByAlice = assumeSupported(sop::certifyUserId)
.noArmor()
.userId("Bob <bob@pgpainless.org>")
.withKeyPassword("sw0rdf1sh")
@ -105,7 +105,7 @@ public class CertifyValidateUserIdTest {
.certs(bobCert)
.getBytes();
assertTrue(sop.validateUserId()
assertTrue(assumeSupported(sop::validateUserId)
.userId("Bob <bob@pgpainless.org>")
.authorities(aliceCert)
.subjects(bobCertifiedByAlice),
@ -115,45 +115,45 @@ public class CertifyValidateUserIdTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void addPetName(SOP sop) throws IOException {
byte[] aliceKey = sop.generateKey()
byte[] aliceKey = assumeSupported(sop::generateKey)
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] aliceCert = sop.extractCert()
byte[] aliceCert = assumeSupported(sop::extractCert)
.key(aliceKey)
.getBytes();
byte[] bobKey = sop.generateKey()
byte[] bobKey = assumeSupported(sop::generateKey)
.userId("Bob <bob@pgpainless.org>")
.generate()
.getBytes();
byte[] bobCert = sop.extractCert()
byte[] bobCert = assumeSupported(sop::extractCert)
.key(bobKey)
.getBytes();
assertThrows(SOPGPException.CertUserIdNoMatch.class, () ->
sop.certifyUserId()
assumeSupported(sop::certifyUserId)
.userId("Bobby")
.keys(aliceKey)
.certs(bobCert)
.getBytes(),
"Alice cannot create a pet-name for Bob without the --no-require-self-sig flag");
byte[] bobWithPetName = sop.certifyUserId()
byte[] bobWithPetName = assumeSupported(sop::certifyUserId)
.userId("Bobby")
.noRequireSelfSig()
.keys(aliceKey)
.certs(bobCert)
.getBytes();
assertTrue(sop.validateUserId()
assertTrue(assumeSupported(sop::validateUserId)
.userId("Bobby")
.authorities(aliceCert)
.subjects(bobWithPetName),
"Alice accepts the pet-name she gave to Bob");
assertThrows(SOPGPException.CertUserIdNoMatch.class, () ->
sop.validateUserId()
assumeSupported(sop::validateUserId)
.userId("Bobby")
.authorities(bobWithPetName)
.subjects(bobWithPetName),
@ -163,28 +163,28 @@ public class CertifyValidateUserIdTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void certifyWithRevokedKey(SOP sop) throws IOException {
byte[] aliceKey = sop.generateKey()
byte[] aliceKey = assumeSupported(sop::generateKey)
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] aliceRevokedCert = sop.revokeKey()
byte[] aliceRevokedCert = assumeSupported(sop::revokeKey)
.keys(aliceKey)
.getBytes();
byte[] aliceRevokedKey = sop.updateKey()
byte[] aliceRevokedKey = assumeSupported(sop::updateKey)
.mergeCerts(aliceRevokedCert)
.key(aliceKey)
.getBytes();
byte[] bobKey = sop.generateKey()
byte[] bobKey = assumeSupported(sop::generateKey)
.userId("Bob <bob@pgpainless.org>")
.generate()
.getBytes();
byte[] bobCert = sop.extractCert()
byte[] bobCert = assumeSupported(sop::extractCert)
.key(bobKey)
.getBytes();
assertThrows(SOPGPException.KeyCannotCertify.class, () ->
sop.certifyUserId()
assumeSupported(sop::certifyUserId)
.userId("Bob <bob@pgpainless.org>")
.keys(aliceRevokedKey)
.certs(bobCert)

View file

@ -32,18 +32,18 @@ public class ChangeKeyPasswordTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void changePasswordFromUnprotectedToProtected(SOP sop) throws IOException {
byte[] unprotectedKey = sop.generateKey().generate().getBytes();
byte[] unprotectedKey = assumeSupported(sop::generateKey).generate().getBytes();
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
byte[] protectedKey = sop.changeKeyPassword().newKeyPassphrase(password).keys(unprotectedKey).getBytes();
byte[] protectedKey = assumeSupported(sop::changeKeyPassword).newKeyPassphrase(password).keys(unprotectedKey).getBytes();
sop.sign().withKeyPassword(password).key(protectedKey).data("Test123".getBytes(StandardCharsets.UTF_8));
assumeSupported(sop::sign).withKeyPassword(password).key(protectedKey).data("Test123".getBytes(StandardCharsets.UTF_8));
}
@ParameterizedTest
@MethodSource("provideInstances")
public void changePasswordFromUnprotectedToUnprotected(SOP sop) throws IOException {
byte[] unprotectedKey = sop.generateKey().noArmor().generate().getBytes();
byte[] stillUnprotectedKey = sop.changeKeyPassword().noArmor().keys(unprotectedKey).getBytes();
byte[] unprotectedKey = assumeSupported(sop::generateKey).noArmor().generate().getBytes();
byte[] stillUnprotectedKey = assumeSupported(sop::changeKeyPassword).noArmor().keys(unprotectedKey).getBytes();
assertArrayEquals(unprotectedKey, stillUnprotectedKey);
}
@ -52,12 +52,12 @@ public class ChangeKeyPasswordTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void changePasswordFromProtectedToUnprotected(SOP sop) throws IOException {
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
byte[] protectedKey = sop.generateKey().withKeyPassword(password).generate().getBytes();
byte[] unprotectedKey = sop.changeKeyPassword()
byte[] protectedKey = assumeSupported(sop::generateKey).withKeyPassword(password).generate().getBytes();
byte[] unprotectedKey = assumeSupported(sop::changeKeyPassword)
.oldKeyPassphrase(password)
.keys(protectedKey).getBytes();
sop.sign().key(unprotectedKey).data("Test123".getBytes(StandardCharsets.UTF_8));
assumeSupported(sop::sign).key(unprotectedKey).data("Test123".getBytes(StandardCharsets.UTF_8));
}
@ParameterizedTest
@ -65,13 +65,13 @@ public class ChangeKeyPasswordTest extends AbstractSOPTest {
public void changePasswordFromProtectedToDifferentProtected(SOP sop) throws IOException {
byte[] oldPassword = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
byte[] newPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
byte[] protectedKey = sop.generateKey().withKeyPassword(oldPassword).generate().getBytes();
byte[] reprotectedKey = sop.changeKeyPassword()
byte[] protectedKey = assumeSupported(sop::generateKey).withKeyPassword(oldPassword).generate().getBytes();
byte[] reprotectedKey = assumeSupported(sop::changeKeyPassword)
.oldKeyPassphrase(oldPassword)
.newKeyPassphrase(newPassword)
.keys(protectedKey).getBytes();
sop.sign().key(reprotectedKey).withKeyPassword(newPassword).data("Test123".getBytes(StandardCharsets.UTF_8));
assumeSupported(sop::sign).key(reprotectedKey).withKeyPassword(newPassword).data("Test123".getBytes(StandardCharsets.UTF_8));
}
@ -82,8 +82,8 @@ public class ChangeKeyPasswordTest extends AbstractSOPTest {
byte[] newPassword = "monkey123".getBytes(UTF8Util.UTF8);
byte[] wrongPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
byte[] protectedKey = sop.generateKey().withKeyPassword(oldPassword).generate().getBytes();
assertThrows(SOPGPException.KeyIsProtected.class, () -> sop.changeKeyPassword()
byte[] protectedKey = assumeSupported(sop::generateKey).withKeyPassword(oldPassword).generate().getBytes();
assertThrows(SOPGPException.KeyIsProtected.class, () -> assumeSupported(sop::changeKeyPassword)
.oldKeyPassphrase(wrongPassword)
.newKeyPassphrase(newPassword)
.keys(protectedKey).getBytes());
@ -93,9 +93,9 @@ public class ChangeKeyPasswordTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void nonUtf8PasswordsFail(SOP sop) {
assertThrows(SOPGPException.PasswordNotHumanReadable.class, () ->
sop.changeKeyPassword().oldKeyPassphrase(new byte[] {(byte) 0xff, (byte) 0xfe}));
assumeSupported(sop::changeKeyPassword).oldKeyPassphrase(new byte[] {(byte) 0xff, (byte) 0xfe}));
assertThrows(SOPGPException.PasswordNotHumanReadable.class, () ->
sop.changeKeyPassword().newKeyPassphrase(new byte[] {(byte) 0xff, (byte) 0xfe}));
assumeSupported(sop::changeKeyPassword).newKeyPassphrase(new byte[] {(byte) 0xff, (byte) 0xfe}));
}
@ -104,16 +104,16 @@ public class ChangeKeyPasswordTest extends AbstractSOPTest {
public void testNoArmor(SOP sop) throws IOException {
byte[] oldPassword = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
byte[] newPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
byte[] protectedKey = sop.generateKey().withKeyPassword(oldPassword).generate().getBytes();
byte[] protectedKey = assumeSupported(sop::generateKey).withKeyPassword(oldPassword).generate().getBytes();
byte[] armored = sop.changeKeyPassword()
byte[] armored = assumeSupported(sop::changeKeyPassword)
.oldKeyPassphrase(oldPassword)
.newKeyPassphrase(newPassword)
.keys(protectedKey)
.getBytes();
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
byte[] unarmored = sop.changeKeyPassword()
byte[] unarmored = assumeSupported(sop::changeKeyPassword)
.noArmor()
.oldKeyPassphrase(oldPassword)
.newKeyPassphrase(newPassword)

View file

@ -41,7 +41,7 @@ public class DecryptWithSessionKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testDecryptAndExtractSessionKey(SOP sop) throws IOException {
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
.toByteArrayAndResult();
@ -54,7 +54,7 @@ public class DecryptWithSessionKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testDecryptWithSessionKey(SOP sop) throws IOException {
byte[] decrypted = sop.decrypt()
byte[] decrypted = assumeSupported(sop::decrypt)
.withSessionKey(SessionKey.fromString(SESSION_KEY))
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
.toByteArrayAndResult()

View file

@ -37,13 +37,13 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
public void signVerifyWithAliceKey(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = sop.detachedSign()
byte[] signature = assumeSupported(sop::detachedSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.toByteArrayAndResult()
.getBytes();
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signature)
.data(message);
@ -60,14 +60,14 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
public void signVerifyTextModeWithAliceKey(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = sop.detachedSign()
byte[] signature = assumeSupported(sop::detachedSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.mode(SignAs.text)
.data(message)
.toByteArrayAndResult()
.getBytes();
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signature)
.data(message);
@ -85,7 +85,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signature)
.data(message);
@ -101,13 +101,13 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
public void signVerifyWithBobKey(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = sop.detachedSign()
byte[] signature = assumeSupported(sop::detachedSign)
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.toByteArrayAndResult()
.getBytes();
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signature)
.data(message);
@ -123,13 +123,13 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
public void signVerifyWithCarolKey(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = sop.detachedSign()
byte[] signature = assumeSupported(sop::detachedSign)
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.toByteArrayAndResult()
.getBytes();
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signature)
.data(message);
@ -145,7 +145,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
public void signVerifyWithEncryptedKey(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = sop.detachedSign()
byte[] signature = assumeSupported(sop::detachedSign)
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
.withKeyPassword(TestData.PASSWORD)
.data(message)
@ -154,7 +154,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
JUtils.assertArrayStartsWith(signature, TestData.BEGIN_PGP_SIGNATURE);
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signature)
.data(message);
@ -170,18 +170,18 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
public void signArmorVerifyWithBobKey(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = sop.detachedSign()
byte[] signature = assumeSupported(sop::detachedSign)
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
.noArmor()
.data(message)
.toByteArrayAndResult()
.getBytes();
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(signature)
.getBytes();
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(armored)
.data(message);
@ -199,7 +199,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
Date beforeSignature = new Date(TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() - 1000); // 1 sec before sig
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
assertThrows(SOPGPException.NoSignature.class, () -> assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.notAfter(beforeSignature)
.signatures(signature)
@ -213,7 +213,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
Date afterSignature = new Date(TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() + 1000); // 1 sec after sig
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
assertThrows(SOPGPException.NoSignature.class, () -> assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.notBefore(afterSignature)
.signatures(signature)
@ -224,13 +224,13 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void signWithAliceVerifyWithBobThrowsNoSignature(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signatures = sop.detachedSign()
byte[] signatures = assumeSupported(sop::detachedSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.toByteArrayAndResult()
.getBytes();
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
assertThrows(SOPGPException.NoSignature.class, () -> assumeSupported(sop::detachedVerify)
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signatures)
.data(message));
@ -240,7 +240,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void signVerifyWithEncryptedKeyWithoutPassphraseFails(SOP sop) {
assertThrows(SOPGPException.KeyIsProtected.class, () ->
sop.detachedSign()
assumeSupported(sop::detachedSign)
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
.data(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
.toByteArrayAndResult()
@ -253,7 +253,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signature = sop.sign()
byte[] signature = assumeSupported(sop::sign)
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
.withKeyPassword("wrong")
.withKeyPassword(TestData.PASSWORD) // correct
@ -262,7 +262,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
.toByteArrayAndResult()
.getBytes();
List<Verification> verificationList = sop.verify()
List<Verification> verificationList = assumeSupported(sop::verify)
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signature)
.data(message);
@ -279,7 +279,7 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
assertThrows(SOPGPException.MissingArg.class, () ->
sop.verify()
assumeSupported(sop::verify)
.signatures(TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8))
.data(message));
}
@ -288,14 +288,14 @@ public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void signVerifyWithMultipleKeys(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signatures = sop.detachedSign()
byte[] signatures = assumeSupported(sop::detachedSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.toByteArrayAndResult()
.getBytes();
List<Verification> verificationList = sop.detachedVerify()
List<Verification> verificationList = assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signatures)

View file

@ -49,7 +49,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void encryptDecryptRoundTripPasswordTest(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
ByteArrayAndResult<EncryptionResult> encResult = sop.encrypt()
ByteArrayAndResult<EncryptionResult> encResult = assumeSupported(sop::encrypt)
.withPassword("sw0rdf1sh")
.plaintext(message)
.toByteArrayAndResult();
@ -57,7 +57,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
byte[] ciphertext = encResult.getBytes();
Optional<SessionKey> encSessionKey = encResult.getResult().getSessionKey();
ByteArrayAndResult<DecryptionResult> decResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> decResult = assumeSupported(sop::decrypt)
.withPassword("sw0rdf1sh")
.ciphertext(ciphertext)
.toByteArrayAndResult();
@ -65,9 +65,10 @@ public class EncryptDecryptTest extends AbstractSOPTest {
byte[] plaintext = decResult.getBytes();
Optional<SessionKey> decSessionKey = decResult.getResult().getSessionKey();
assertArrayEquals(message, plaintext);
assertArrayEquals(message, plaintext, "Decrypted plaintext does not match original plaintext.");
if (encSessionKey.isPresent() && decSessionKey.isPresent()) {
assertEquals(encSessionKey.get(), decSessionKey.get());
assertEquals(encSessionKey.get(), decSessionKey.get(),
"Extracted Session Key mismatch.");
}
}
@ -75,91 +76,93 @@ public class EncryptDecryptTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void encryptDecryptRoundTripAliceTest(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = sop.encrypt()
byte[] ciphertext = assumeSupported(sop::encrypt)
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.ciphertext(ciphertext)
.toByteArrayAndResult();
byte[] plaintext = bytesAndResult.getBytes();
assertArrayEquals(message, plaintext);
assertArrayEquals(message, plaintext, "Decrypted plaintext does not match original plaintext.");
DecryptionResult result = bytesAndResult.getResult();
assertNotNull(result.getSessionKey().get());
if (result.getSessionKey().isPresent()) {
assertNotNull(result.getSessionKey().get(), "Session key MUST NOT be null.");
}
}
@ParameterizedTest
@MethodSource("provideInstances")
public void encryptDecryptRoundTripBobTest(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = sop.encrypt()
byte[] ciphertext = assumeSupported(sop::encrypt)
.withCert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
byte[] plaintext = sop.decrypt()
byte[] plaintext = assumeSupported(sop::decrypt)
.withKey(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
.ciphertext(ciphertext)
.toByteArrayAndResult()
.getBytes();
assertArrayEquals(message, plaintext);
assertArrayEquals(message, plaintext, "Decrypted plaintext does not match original plaintext.");
}
@ParameterizedTest
@MethodSource("provideInstances")
public void encryptDecryptRoundTripCarolTest(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = sop.encrypt()
byte[] ciphertext = assumeSupported(sop::encrypt)
.withCert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
byte[] plaintext = sop.decrypt()
byte[] plaintext = assumeSupported(sop::decrypt)
.withKey(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
.ciphertext(ciphertext)
.toByteArrayAndResult()
.getBytes();
assertArrayEquals(message, plaintext);
assertArrayEquals(message, plaintext, "Decrypted plaintext does not match original plaintext.");
}
@ParameterizedTest
@MethodSource("provideInstances")
public void encryptNoArmorThenArmorThenDecryptRoundTrip(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = sop.encrypt()
byte[] ciphertext = assumeSupported(sop::encrypt)
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.noArmor()
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(ciphertext)
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.ciphertext(armored)
.toByteArrayAndResult();
byte[] plaintext = bytesAndResult.getBytes();
assertArrayEquals(message, plaintext);
assertArrayEquals(message, plaintext, "Decrypted plaintext does not match original plaintext.");
}
@ParameterizedTest
@MethodSource("provideInstances")
public void encryptSignDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = sop.encrypt()
byte[] ciphertext = assumeSupported(sop::encrypt)
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.mode(EncryptAs.binary)
@ -167,17 +170,19 @@ public class EncryptDecryptTest extends AbstractSOPTest {
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.ciphertext(ciphertext)
.toByteArrayAndResult();
byte[] plaintext = bytesAndResult.getBytes();
assertArrayEquals(message, plaintext);
assertArrayEquals(message, plaintext, "Decrypted plaintext does not match original plaintext.");
DecryptionResult result = bytesAndResult.getResult();
assertNotNull(result.getSessionKey().get());
if (result.getSessionKey().isPresent()) {
assertNotNull(result.getSessionKey().get(), "Session key MUST NOT be null.");
}
List<Verification> verificationList = result.getVerifications();
VerificationListAssert.assertThatVerificationList(verificationList)
@ -191,7 +196,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void encryptSignAsTextDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = sop.encrypt()
byte[] ciphertext = assumeSupported(sop::encrypt)
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.mode(EncryptAs.text)
@ -199,14 +204,14 @@ public class EncryptDecryptTest extends AbstractSOPTest {
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.ciphertext(ciphertext)
.toByteArrayAndResult();
byte[] plaintext = bytesAndResult.getBytes();
assertArrayEquals(message, plaintext);
assertArrayEquals(message, plaintext, "Decrypted plaintext does not match original plaintext.");
DecryptionResult result = bytesAndResult.getResult();
assertNotNull(result.getSessionKey().get());
@ -222,17 +227,17 @@ public class EncryptDecryptTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void encryptSignDecryptVerifyRoundTripWithFreshEncryptedKeyTest(SOP sop) throws IOException {
byte[] keyPassword = "sw0rdf1sh".getBytes(StandardCharsets.UTF_8);
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.withKeyPassword(keyPassword)
.userId("Alice <alice@openpgp.org>")
.generate()
.getBytes();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.key(key)
.getBytes();
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
byte[] ciphertext = sop.encrypt()
byte[] ciphertext = assumeSupported(sop::encrypt)
.withCert(cert)
.signWith(key)
.withKeyPassword(keyPassword)
@ -240,7 +245,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(key)
.withKeyPassword(keyPassword)
.verifyWithCert(cert)
@ -273,7 +278,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before signing date
assertThrows(SOPGPException.NoSignature.class, () -> {
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.verifyNotAfter(beforeSignature)
@ -307,7 +312,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec after signing date
assertThrows(SOPGPException.NoSignature.class, () -> {
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
ByteArrayAndResult<DecryptionResult> bytesAndResult = assumeSupported(sop::decrypt)
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.verifyNotBefore(afterSignature)
@ -326,7 +331,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
public void missingArgsTest(SOP sop) {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
assertThrows(SOPGPException.MissingArg.class, () -> sop.encrypt()
assertThrows(SOPGPException.MissingArg.class, () -> assumeSupported(sop::encrypt)
.plaintext(message)
.toByteArrayAndResult()
.getBytes());
@ -336,7 +341,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void passingSecretKeysForPublicKeysFails(SOP sop) {
assertThrows(SOPGPException.BadData.class, () ->
sop.encrypt()
assumeSupported(sop::encrypt)
.withCert(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
.toByteArrayAndResult()
@ -346,19 +351,19 @@ public class EncryptDecryptTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void encryptDecryptWithAllSupportedKeyGenerationProfiles(SOP sop) throws IOException {
List<Profile> profiles = sop.listProfiles().generateKey();
List<Profile> profiles = assumeSupported(sop::listProfiles).generateKey();
List<byte[]> keys = new ArrayList<>();
List<byte[]> certs = new ArrayList<>();
for (Profile p : profiles) {
byte[] k = sop.generateKey()
byte[] k = assumeSupported(sop::generateKey)
.profile(p)
.userId(p.getName())
.generate()
.getBytes();
keys.add(k);
byte[] c = sop.extractCert()
byte[] c = assumeSupported(sop::extractCert)
.key(k)
.getBytes();
certs.add(c);
@ -366,7 +371,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
byte[] plaintext = "Hello, World!\n".getBytes();
Encrypt encrypt = sop.encrypt();
Encrypt encrypt = assumeSupported(sop::encrypt);
for (byte[] c : certs) {
encrypt.withCert(c);
}
@ -380,7 +385,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
byte[] ciphertext = encRes.getBytes();
for (byte[] k : keys) {
Decrypt decrypt = sop.decrypt()
Decrypt decrypt = assumeSupported(sop::decrypt)
.withKey(k);
for (byte[] c : certs) {
decrypt.verifyWithCert(c);
@ -389,7 +394,7 @@ public class EncryptDecryptTest extends AbstractSOPTest {
.toByteArrayAndResult();
DecryptionResult dResult = decRes.getResult();
byte[] decPlaintext = decRes.getBytes();
assertArrayEquals(plaintext, decPlaintext);
assertArrayEquals(plaintext, decPlaintext, "Decrypted plaintext does not match original plaintext.");
assertEquals(certs.size(), dResult.getVerifications().size());
}
}

View file

@ -28,12 +28,12 @@ public class ExtractCertTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void extractArmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
InputStream keyIn = sop.generateKey()
InputStream keyIn = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.generate()
.getInputStream();
byte[] cert = sop.extractCert().key(keyIn).getBytes();
byte[] cert = assumeSupported(sop::extractCert).key(keyIn).getBytes();
JUtils.assertArrayStartsWith(cert, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK);
JUtils.assertArrayEndsWithIgnoreNewlines(cert, TestData.END_PGP_PUBLIC_KEY_BLOCK);
}
@ -41,7 +41,7 @@ public class ExtractCertTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void extractAliceCertFromAliceKeyTest(SOP sop) throws IOException {
byte[] armoredCert = sop.extractCert()
byte[] armoredCert = assumeSupported(sop::extractCert)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.getBytes();
JUtils.assertAsciiArmorEquals(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
@ -50,7 +50,7 @@ public class ExtractCertTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void extractBobsCertFromBobsKeyTest(SOP sop) throws IOException {
byte[] armoredCert = sop.extractCert()
byte[] armoredCert = assumeSupported(sop::extractCert)
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
.getBytes();
JUtils.assertAsciiArmorEquals(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
@ -59,7 +59,7 @@ public class ExtractCertTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void extractCarolsCertFromCarolsKeyTest(SOP sop) throws IOException {
byte[] armoredCert = sop.extractCert()
byte[] armoredCert = assumeSupported(sop::extractCert)
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
.getBytes();
JUtils.assertAsciiArmorEquals(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
@ -68,12 +68,12 @@ public class ExtractCertTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void extractUnarmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
InputStream keyIn = sop.generateKey()
InputStream keyIn = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.generate()
.getInputStream();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.noArmor()
.key(keyIn)
.getBytes();
@ -84,13 +84,13 @@ public class ExtractCertTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void extractArmoredCertFromUnarmoredKeyTest(SOP sop) throws IOException {
InputStream keyIn = sop.generateKey()
InputStream keyIn = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.noArmor()
.generate()
.getInputStream();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.key(keyIn)
.getBytes();
@ -101,13 +101,13 @@ public class ExtractCertTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void extractUnarmoredCertFromUnarmoredKeyTest(SOP sop) throws IOException {
InputStream keyIn = sop.generateKey()
InputStream keyIn = assumeSupported(sop::generateKey)
.noArmor()
.userId("Alice <alice@openpgp.org>")
.generate()
.getInputStream();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.noArmor()
.key(keyIn)
.getBytes();

View file

@ -33,7 +33,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateKeyTest(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.generate()
.getBytes();
@ -45,7 +45,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateKeyNoArmor(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.noArmor()
.generate()
@ -57,7 +57,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateKeyWithMultipleUserIdsTest(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.userId("Bob <bob@openpgp.org>")
.generate()
@ -70,7 +70,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateKeyWithoutUserIdTest(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.generate()
.getBytes();
@ -81,7 +81,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateKeyWithPasswordTest(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.withKeyPassword("sw0rdf1sh")
.generate()
@ -94,7 +94,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateKeyWithMultipleUserIdsAndPassword(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@openpgp.org>")
.userId("Bob <bob@openpgp.org>")
.withKeyPassword("sw0rdf1sh")
@ -108,17 +108,17 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateSigningOnlyKey(SOP sop) throws IOException {
byte[] signingOnlyKey = sop.generateKey()
byte[] signingOnlyKey = assumeSupported(sop::generateKey)
.signingOnly()
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] signingOnlyCert = sop.extractCert()
byte[] signingOnlyCert = assumeSupported(sop::extractCert)
.key(signingOnlyKey)
.getBytes();
assertThrows(SOPGPException.CertCannotEncrypt.class, () ->
sop.encrypt().withCert(signingOnlyCert)
assumeSupported(sop::encrypt).withCert(signingOnlyCert)
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
.toByteArrayAndResult()
.getBytes());
@ -127,7 +127,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void generateKeyWithSupportedProfiles(SOP sop) throws IOException {
List<Profile> profiles = sop.listProfiles()
List<Profile> profiles = assumeSupported(sop::listProfiles)
.generateKey();
for (Profile profile : profiles) {
@ -138,7 +138,7 @@ public class GenerateKeyTest extends AbstractSOPTest {
private void generateKeyWithProfile(SOP sop, String profile) throws IOException {
byte[] key;
try {
key = sop.generateKey()
key = assumeSupported(sop::generateKey)
.profile(profile)
.userId("Alice <alice@pgpainless.org>")
.generate()

View file

@ -36,12 +36,12 @@ public class InlineSignInlineDetachDetachedVerifyTest extends AbstractSOPTest {
public void inlineSignThenDetachThenDetachedVerifyTest(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] inlineSigned = sop.inlineSign()
byte[] inlineSigned = assumeSupported(sop::inlineSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.getBytes();
ByteArrayAndResult<Signatures> bytesAndResult = sop.inlineDetach()
ByteArrayAndResult<Signatures> bytesAndResult = assumeSupported(sop::inlineDetach)
.message(inlineSigned)
.toByteArrayAndResult();
@ -51,7 +51,7 @@ public class InlineSignInlineDetachDetachedVerifyTest extends AbstractSOPTest {
byte[] signatures = bytesAndResult.getResult()
.getBytes();
List<Verification> verifications = sop.detachedVerify()
List<Verification> verifications = assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(signatures)
.data(plaintext);
@ -64,12 +64,12 @@ public class InlineSignInlineDetachDetachedVerifyTest extends AbstractSOPTest {
public void inlineSignThenDetachNoArmorThenArmorThenDetachedVerifyTest(SOP sop) throws IOException {
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
byte[] inlineSigned = sop.inlineSign()
byte[] inlineSigned = assumeSupported(sop::inlineSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.getBytes();
ByteArrayAndResult<Signatures> bytesAndResult = sop.inlineDetach()
ByteArrayAndResult<Signatures> bytesAndResult = assumeSupported(sop::inlineDetach)
.noArmor()
.message(inlineSigned)
.toByteArrayAndResult();
@ -81,12 +81,12 @@ public class InlineSignInlineDetachDetachedVerifyTest extends AbstractSOPTest {
.getBytes();
Assertions.assertFalse(JUtils.arrayStartsWith(signatures, TestData.BEGIN_PGP_SIGNATURE));
byte[] armored = sop.armor()
byte[] armored = assumeSupported(sop::armor)
.data(signatures)
.getBytes();
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_SIGNATURE);
List<Verification> verifications = sop.detachedVerify()
List<Verification> verifications = assumeSupported(sop::detachedVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.signatures(armored)
.data(plaintext);

View file

@ -40,14 +40,14 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
public void inlineSignVerifyAlice(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] inlineSigned = sop.inlineSign()
byte[] inlineSigned = assumeSupported(sop::inlineSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.getBytes();
JUtils.assertArrayStartsWith(inlineSigned, TestData.BEGIN_PGP_MESSAGE);
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
ByteArrayAndResult<List<Verification>> bytesAndResult = assumeSupported(sop::inlineVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.data(inlineSigned)
.toByteArrayAndResult();
@ -66,7 +66,7 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
public void inlineSignVerifyAliceNoArmor(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] inlineSigned = sop.inlineSign()
byte[] inlineSigned = assumeSupported(sop::inlineSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.noArmor()
.data(message)
@ -74,7 +74,7 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
Assertions.assertFalse(JUtils.arrayStartsWith(inlineSigned, TestData.BEGIN_PGP_MESSAGE));
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
ByteArrayAndResult<List<Verification>> bytesAndResult = assumeSupported(sop::inlineVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.data(inlineSigned)
.toByteArrayAndResult();
@ -93,7 +93,7 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
public void clearsignVerifyAlice(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] clearsigned = sop.inlineSign()
byte[] clearsigned = assumeSupported(sop::inlineSign)
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
.mode(InlineSignAs.clearsigned)
.data(message)
@ -101,12 +101,13 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
JUtils.assertArrayStartsWith(clearsigned, TestData.BEGIN_PGP_SIGNED_MESSAGE);
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
ByteArrayAndResult<List<Verification>> bytesAndResult = assumeSupported(sop::inlineVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.data(clearsigned)
.toByteArrayAndResult();
assertArrayEquals(message, bytesAndResult.getBytes());
assertArrayEquals(message, bytesAndResult.getBytes(),
"ASCII armored message does not appear to start with the 'BEGIN PGP SIGNED MESSAGE' header.");
List<Verification> verificationList = bytesAndResult.getResult();
VerificationListAssert.assertThatVerificationList(verificationList)
@ -121,7 +122,7 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
ByteArrayAndResult<List<Verification>> bytesAndResult = assumeSupported(sop::inlineVerify)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.data(message)
.toByteArrayAndResult();
@ -141,7 +142,7 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec before sig
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
assertThrows(SOPGPException.NoSignature.class, () -> assumeSupported(sop::inlineVerify)
.notBefore(afterSignature)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.data(message)
@ -155,7 +156,7 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before sig
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
assertThrows(SOPGPException.NoSignature.class, () -> assumeSupported(sop::inlineVerify)
.notAfter(beforeSignature)
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
.data(message)
@ -167,14 +168,14 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
public void inlineSignVerifyBob(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] inlineSigned = sop.inlineSign()
byte[] inlineSigned = assumeSupported(sop::inlineSign)
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.getBytes();
JUtils.assertArrayStartsWith(inlineSigned, TestData.BEGIN_PGP_MESSAGE);
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
ByteArrayAndResult<List<Verification>> bytesAndResult = assumeSupported(sop::inlineVerify)
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
.data(inlineSigned)
.toByteArrayAndResult();
@ -193,14 +194,14 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
public void inlineSignVerifyCarol(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] inlineSigned = sop.inlineSign()
byte[] inlineSigned = assumeSupported(sop::inlineSign)
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
.data(message)
.getBytes();
JUtils.assertArrayStartsWith(inlineSigned, TestData.BEGIN_PGP_MESSAGE);
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
ByteArrayAndResult<List<Verification>> bytesAndResult = assumeSupported(sop::inlineVerify)
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
.data(inlineSigned)
.toByteArrayAndResult();
@ -219,14 +220,14 @@ public class InlineSignInlineVerifyTest extends AbstractSOPTest {
public void inlineSignVerifyProtectedKey(SOP sop) throws IOException {
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] inlineSigned = sop.inlineSign()
byte[] inlineSigned = assumeSupported(sop::inlineSign)
.withKeyPassword(TestData.PASSWORD)
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
.mode(InlineSignAs.binary)
.data(message)
.getBytes();
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
ByteArrayAndResult<List<Verification>> bytesAndResult = assumeSupported(sop::inlineVerify)
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
.data(inlineSigned)
.toByteArrayAndResult();

View file

@ -26,8 +26,7 @@ public class ListProfilesTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void listGenerateKeyProfiles(SOP sop) {
List<Profile> profiles = sop
.listProfiles()
List<Profile> profiles = assumeSupported(sop::listProfiles)
.generateKey();
assertFalse(profiles.isEmpty());
@ -36,8 +35,7 @@ public class ListProfilesTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void listEncryptProfiles(SOP sop) {
List<Profile> profiles = sop
.listProfiles()
List<Profile> profiles = assumeSupported(sop::listProfiles)
.encrypt();
assertFalse(profiles.isEmpty());
@ -46,8 +44,7 @@ public class ListProfilesTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void listUnsupportedProfiles(SOP sop) {
assertThrows(SOPGPException.UnsupportedProfile.class, () -> sop
.listProfiles()
assertThrows(SOPGPException.UnsupportedProfile.class, () -> assumeSupported(sop::listProfiles)
.subcommand("invalid"));
}
}

View file

@ -24,16 +24,16 @@ public class MergeCertsTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testMergeWithItself(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.key(key)
.getBytes();
byte[] merged = sop.mergeCerts()
byte[] merged = assumeSupported(sop::mergeCerts)
.updates(cert)
.baseCertificates(cert)
.getBytes();
@ -44,17 +44,17 @@ public class MergeCertsTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testMergeWithItselfArmored(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.noArmor()
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.key(key)
.getBytes();
byte[] merged = sop.mergeCerts()
byte[] merged = assumeSupported(sop::mergeCerts)
.updates(cert)
.baseCertificates(cert)
.getBytes();
@ -65,18 +65,18 @@ public class MergeCertsTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testMergeWithItselfViaBase(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.key(key)
.getBytes();
byte[] certs = ArraysKt.plus(cert, cert);
byte[] merged = sop.mergeCerts()
byte[] merged = assumeSupported(sop::mergeCerts)
.updates(cert)
.baseCertificates(certs)
.getBytes();
@ -87,20 +87,20 @@ public class MergeCertsTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testApplyBaseToUpdate(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.key(key)
.getBytes();
byte[] update = sop.revokeKey()
byte[] update = assumeSupported(sop::revokeKey)
.keys(key)
.getBytes();
byte[] merged = sop.mergeCerts()
byte[] merged = assumeSupported(sop::mergeCerts)
.updates(cert)
.baseCertificates(update)
.getBytes();
@ -111,20 +111,20 @@ public class MergeCertsTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testApplyUpdateToBase(SOP sop) throws IOException {
byte[] key = sop.generateKey()
byte[] key = assumeSupported(sop::generateKey)
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] cert = sop.extractCert()
byte[] cert = assumeSupported(sop::extractCert)
.key(key)
.getBytes();
byte[] update = sop.revokeKey()
byte[] update = assumeSupported(sop::revokeKey)
.keys(key)
.getBytes();
byte[] merged = sop.mergeCerts()
byte[] merged = assumeSupported(sop::mergeCerts)
.updates(update)
.baseCertificates(cert)
.getBytes();
@ -135,25 +135,25 @@ public class MergeCertsTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void testApplyUpdateToMissingBaseDoesNothing(SOP sop) throws IOException {
byte[] aliceKey = sop.generateKey()
byte[] aliceKey = assumeSupported(sop::generateKey)
.userId("Alice <alice@pgpainless.org>")
.generate()
.getBytes();
byte[] aliceCert = sop.extractCert()
byte[] aliceCert = assumeSupported(sop::extractCert)
.key(aliceKey)
.getBytes();
byte[] bobKey = sop.generateKey()
byte[] bobKey = assumeSupported(sop::generateKey)
.userId("Bob <bob@pgpainless.org>")
.generate()
.getBytes();
byte[] bobCert = sop.extractCert()
byte[] bobCert = assumeSupported(sop::extractCert)
.key(bobKey)
.getBytes();
byte[] merged = sop.mergeCerts()
byte[] merged = assumeSupported(sop::mergeCerts)
.updates(bobCert)
.baseCertificates(aliceCert)
.getBytes();

View file

@ -36,8 +36,8 @@ public class RevokeKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void revokeUnprotectedKey(SOP sop) throws IOException {
byte[] secretKey = sop.generateKey().userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = sop.revokeKey().keys(secretKey).getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = assumeSupported(sop::revokeKey).keys(secretKey).getBytes();
assertTrue(JUtils.arrayStartsWith(revocation, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
assertFalse(Arrays.equals(secretKey, revocation));
@ -46,8 +46,8 @@ public class RevokeKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void revokeUnprotectedKeyNoArmor(SOP sop) throws IOException {
byte[] secretKey = sop.generateKey().userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = sop.revokeKey().noArmor().keys(secretKey).getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = assumeSupported(sop::revokeKey).noArmor().keys(secretKey).getBytes();
assertFalse(JUtils.arrayStartsWith(revocation, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
}
@ -55,8 +55,8 @@ public class RevokeKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void revokeUnprotectedKeyUnarmored(SOP sop) throws IOException {
byte[] secretKey = sop.generateKey().userId("Alice <alice@pgpainless.org>").noArmor().generate().getBytes();
byte[] revocation = sop.revokeKey().noArmor().keys(secretKey).getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).userId("Alice <alice@pgpainless.org>").noArmor().generate().getBytes();
byte[] revocation = assumeSupported(sop::revokeKey).noArmor().keys(secretKey).getBytes();
assertFalse(JUtils.arrayStartsWith(revocation, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
assertFalse(Arrays.equals(secretKey, revocation));
@ -65,18 +65,18 @@ public class RevokeKeyTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void revokeCertificateFails(SOP sop) throws IOException {
byte[] secretKey = sop.generateKey().generate().getBytes();
byte[] certificate = sop.extractCert().key(secretKey).getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).generate().getBytes();
byte[] certificate = assumeSupported(sop::extractCert).key(secretKey).getBytes();
assertThrows(SOPGPException.BadData.class, () -> sop.revokeKey().keys(certificate).getBytes());
assertThrows(SOPGPException.BadData.class, () -> assumeSupported(sop::revokeKey).keys(certificate).getBytes());
}
@ParameterizedTest
@MethodSource("provideInstances")
public void revokeProtectedKey(SOP sop) throws IOException {
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = sop.revokeKey().withKeyPassword(password).keys(secretKey).getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = assumeSupported(sop::revokeKey).withKeyPassword(password).keys(secretKey).getBytes();
assertFalse(Arrays.equals(secretKey, revocation));
}
@ -86,8 +86,8 @@ public class RevokeKeyTest extends AbstractSOPTest {
public void revokeProtectedKeyWithMultiplePasswordOptions(SOP sop) throws IOException {
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
byte[] wrongPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = sop.revokeKey().withKeyPassword(wrongPassword).withKeyPassword(password).keys(secretKey).getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] revocation = assumeSupported(sop::revokeKey).withKeyPassword(wrongPassword).withKeyPassword(password).keys(secretKey).getBytes();
assertFalse(Arrays.equals(secretKey, revocation));
}
@ -96,9 +96,9 @@ public class RevokeKeyTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void revokeProtectedKeyWithMissingPassphraseFails(SOP sop) throws IOException {
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
assertThrows(SOPGPException.KeyIsProtected.class, () -> sop.revokeKey().keys(secretKey).getBytes());
assertThrows(SOPGPException.KeyIsProtected.class, () -> assumeSupported(sop::revokeKey).keys(secretKey).getBytes());
}
@ParameterizedTest
@ -106,27 +106,27 @@ public class RevokeKeyTest extends AbstractSOPTest {
public void revokeProtectedKeyWithWrongPassphraseFails(SOP sop) throws IOException {
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
String wrongPassword = "or4ng3";
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
byte[] secretKey = assumeSupported(sop::generateKey).withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
assertThrows(SOPGPException.KeyIsProtected.class, () -> sop.revokeKey().withKeyPassword(wrongPassword).keys(secretKey).getBytes());
assertThrows(SOPGPException.KeyIsProtected.class, () -> assumeSupported(sop::revokeKey).withKeyPassword(wrongPassword).keys(secretKey).getBytes());
}
@ParameterizedTest
@MethodSource("provideInstances")
public void revokeKeyIsNowHardRevoked(SOP sop) throws IOException {
byte[] key = sop.generateKey().generate().getBytes();
byte[] cert = sop.extractCert().key(key).getBytes();
byte[] key = assumeSupported(sop::generateKey).generate().getBytes();
byte[] cert = assumeSupported(sop::extractCert).key(key).getBytes();
// Sign a message with the key
byte[] msg = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
byte[] signedMsg = sop.inlineSign().key(key).data(msg).getBytes();
byte[] signedMsg = assumeSupported(sop::inlineSign).key(key).data(msg).getBytes();
// Verifying the message with the valid cert works
List<Verification> result = sop.inlineVerify().cert(cert).data(signedMsg).toByteArrayAndResult().getResult();
List<Verification> result = assumeSupported(sop::inlineVerify).cert(cert).data(signedMsg).toByteArrayAndResult().getResult();
VerificationListAssert.assertThatVerificationList(result).hasSingleItem();
// Now hard revoke the key and re-check signature, expecting no valid certification
byte[] revokedCert = sop.revokeKey().keys(key).getBytes();
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify().cert(revokedCert).data(signedMsg).toByteArrayAndResult());
byte[] revokedCert = assumeSupported(sop::revokeKey).keys(key).getBytes();
assertThrows(SOPGPException.NoSignature.class, () -> assumeSupported(sop::inlineVerify).cert(revokedCert).data(signedMsg).toByteArrayAndResult());
}
}

View file

@ -28,7 +28,7 @@ public class VersionTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void versionNameTest(SOP sop) {
String name = sop.version().getName();
String name = assumeSupported(sop::version).getName();
assertNotNull(name);
assertFalse(name.isEmpty());
}
@ -36,21 +36,21 @@ public class VersionTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void versionVersionTest(SOP sop) {
String version = sop.version().getVersion();
String version = assumeSupported(sop::version).getVersion();
assertFalse(version.isEmpty());
}
@ParameterizedTest
@MethodSource("provideInstances")
public void backendVersionTest(SOP sop) {
String backend = sop.version().getBackendVersion();
String backend = assumeSupported(sop::version).getBackendVersion();
assertFalse(backend.isEmpty());
}
@ParameterizedTest
@MethodSource("provideInstances")
public void extendedVersionTest(SOP sop) {
String extended = sop.version().getExtendedVersion();
String extended = assumeSupported(sop::version).getExtendedVersion();
assertFalse(extended.isEmpty());
}
@ -58,27 +58,27 @@ public class VersionTest extends AbstractSOPTest {
@MethodSource("provideInstances")
public void sopSpecVersionTest(SOP sop) {
try {
sop.version().getSopSpecVersion();
assumeSupported(sop::version).getSopSpecVersion();
} catch (RuntimeException e) {
throw new TestAbortedException("SOP backend does not support 'version --sop-spec' yet.");
}
String sopSpec = sop.version().getSopSpecVersion();
if (sop.version().isSopSpecImplementationIncomplete()) {
String sopSpec = assumeSupported(sop::version).getSopSpecVersion();
if (assumeSupported(sop::version).isSopSpecImplementationIncomplete()) {
assertTrue(sopSpec.startsWith("~draft-dkg-openpgp-stateless-cli-"));
} else {
assertTrue(sopSpec.startsWith("draft-dkg-openpgp-stateless-cli-"));
}
int sopRevision = sop.version().getSopSpecRevisionNumber();
assertTrue(sop.version().getSopSpecRevisionName().endsWith("" + sopRevision));
int sopRevision = assumeSupported(sop::version).getSopSpecRevisionNumber();
assertTrue(assumeSupported(sop::version).getSopSpecRevisionName().endsWith("" + sopRevision));
}
@ParameterizedTest
@MethodSource("provideInstances")
public void sopVVersionTest(SOP sop) {
try {
sop.version().getSopVVersion();
assumeSupported(sop::version).getSopVVersion();
} catch (SOPGPException.UnsupportedOption e) {
throw new TestAbortedException(
"Implementation does (gracefully) not provide coverage for any sopv interface version.");
@ -90,6 +90,6 @@ public class VersionTest extends AbstractSOPTest {
@ParameterizedTest
@MethodSource("provideInstances")
public void sopJavaVersionTest(SOP sop) {
assertNotNull(sop.version().getSopJavaVersion());
assertNotNull(assumeSupported(sop::version).getSopJavaVersion());
}
}

View file

@ -7,6 +7,7 @@ package sop;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import sop.enums.SignatureMode;
import sop.testsuite.assertions.VerificationAssert;
import java.text.ParseException;
import java.util.ArrayList;
@ -158,6 +159,8 @@ public class VerificationJSONTest {
assertNull(json.getExt());
verification = new Verification(verification.getCreationTime(), verification.getSigningKeyFingerprint(), verification.getSigningCertFingerprint(), verification.getSignatureMode().get(), json, dummySerializer);
VerificationAssert.assertThatVerification(verification)
.hasJSON(dummyParser, j -> j.getSigners().contains("alice.pgp"));
assertEquals(string, verification.toString());
}
}