1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 18:29:39 +02:00

Replace static decryptAndOrVerify() method with non-static processMessage() function

This commit is contained in:
Paul Schaub 2025-05-06 22:21:02 +02:00
parent 7062681d03
commit 9ed53308c6
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
53 changed files with 141 additions and 129 deletions

View file

@ -112,6 +112,12 @@ class PGPainless(
/** Generate an encrypted and/or signed OpenPGP message. */
fun generateMessage(): EncryptionBuilder = EncryptionBuilder(this)
/**
* Process an OpenPGP message. This method attempts decryption of encrypted messages and
* performs signature verification.
*/
fun processMessage(): DecryptionBuilder = DecryptionBuilder(this)
/**
* Create certification signatures on third-party [OpenPGPCertificates][OpenPGPCertificate].
*
@ -253,7 +259,11 @@ class PGPainless(
*
* @return builder
*/
@JvmStatic fun decryptAndOrVerify(): DecryptionBuilder = DecryptionBuilder(getInstance())
@Deprecated(
"Call processMessage() on an instance of PGPainless instead.",
replaceWith = ReplaceWith("processMessage()"))
@JvmStatic
fun decryptAndOrVerify(): DecryptionBuilder = getInstance().processMessage()
/**
* Make changes to a secret key at the given reference time. This method can be used to

View file

@ -35,7 +35,7 @@ interface SymmetricKeyAlgorithmNegotiator {
override: SymmetricKeyAlgorithm?,
keyPreferences: List<Set<SymmetricKeyAlgorithm>>
): SymmetricKeyAlgorithm {
require (override != SymmetricKeyAlgorithm.NULL) {
require(override != SymmetricKeyAlgorithm.NULL) {
"Algorithm override cannot be NULL (plaintext)."
}

View file

@ -405,7 +405,8 @@ class EncryptionOptions(private val purpose: EncryptionPurpose, private val api:
}
fun overrideEncryptionMechanism(encryptionMechanism: MessageEncryptionMechanism) = apply {
require(api.algorithmPolicy.symmetricKeyEncryptionAlgorithmPolicy.isAcceptable(
require(
api.algorithmPolicy.symmetricKeyEncryptionAlgorithmPolicy.isAcceptable(
encryptionMechanism.symmetricKeyAlgorithm)) {
"Provided symmetric encryption algorithm is not acceptable."
}

View file

@ -187,7 +187,7 @@ public class InvestigateMultiSEIPMessageHandlingTest {
.addVerificationCert(ring2)
.addDecryptionKey(ring1);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(MESSAGE.getBytes(StandardCharsets.UTF_8)))
.withOptions(options);

View file

@ -122,7 +122,7 @@ public class OnePassSignatureVerificationWithPartialLengthLiteralDataRegressionT
ByteArrayInputStream in = new ByteArrayInputStream(dearmored.toByteArray());
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addVerificationCert(cert)

View file

@ -542,7 +542,7 @@ public class AsciiArmorCRCTests {
OpenPGPKey key = PGPainless.getInstance().readKey().parseKey(ASCII_KEY);
assertThrows(IOException.class, () -> {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get().addDecryptionKey(
key, SecretKeyRingProtector.unlockAnyKeyWith(passphrase)

View file

@ -76,7 +76,7 @@ public class CachingBcPublicKeyDataDecryptorFactoryTest {
privateKey, decryptionKey);
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(MSG.getBytes());
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(ciphertextIn)
.withOptions(ConsumerOptions.get()
.addCustomDecryptorFactory(cachingFactory));
@ -87,7 +87,7 @@ public class CachingBcPublicKeyDataDecryptorFactoryTest {
assertEquals("Hello, World!\n", out.toString());
ciphertextIn = new ByteArrayInputStream(MSG.getBytes());
decryptionStream = PGPainless.decryptAndOrVerify()
decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(ciphertextIn)
.withOptions(ConsumerOptions.get()
.addCustomDecryptorFactory(cachingFactory));

View file

@ -297,7 +297,7 @@ public class CanonicalizedDataEncryptionTest {
String encrypted = encryptAndSign(before, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.TEXT, true);
ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys())
@ -327,7 +327,7 @@ public class CanonicalizedDataEncryptionTest {
String encrypted = encryptAndSign(beforeAndAfter, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.TEXT, false);
ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys())
@ -359,7 +359,7 @@ public class CanonicalizedDataEncryptionTest {
options.applyCRLFEncoding();
}
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
EncryptionStream encryptionStream = PGPainless.getInstance().generateMessage()
.onOutputStream(out)
.withOptions(options);
@ -373,7 +373,7 @@ public class CanonicalizedDataEncryptionTest {
private MessageMetadata decryptAndVerify(String msg) throws PGPException, IOException {
ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys())
@ -444,7 +444,7 @@ public class CanonicalizedDataEncryptionTest {
ByteArrayInputStream cipherIn = new ByteArrayInputStream(ciphertext.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream decrypted = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(cipherIn)
.withOptions(ConsumerOptions.get()
.addVerificationCert(publicKeys));

View file

@ -144,7 +144,7 @@ public class CertificateWithMissingSecretKeyTest {
.addDecryptionKey(missingDecryptionSecKey);
assertThrows(MissingDecryptionMethodException.class, () ->
PGPainless.decryptAndOrVerify()
api.processMessage()
.onInputStream(cipherIn)
.withOptions(consumerOptions)); // <- cannot find decryption key
}

View file

@ -83,7 +83,7 @@ public class CleartextSignatureVerificationTest {
InMemoryMultiPassStrategy multiPassStrategy = MultiPassStrategy.keepMessageInMemory();
options.setMultiPassStrategy(multiPassStrategy);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(MESSAGE_SIGNED))
.withOptions(options);
@ -112,7 +112,7 @@ public class CleartextSignatureVerificationTest {
File file = new File(tempDir, "file");
MultiPassStrategy multiPassStrategy = MultiPassStrategy.writeMessageToFile(file);
options.setMultiPassStrategy(multiPassStrategy);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(MESSAGE_SIGNED))
.withOptions(options);
@ -152,7 +152,7 @@ public class CleartextSignatureVerificationTest {
.addVerificationCert(TestKeys.getEmilCertificate())
.addVerificationOfDetachedSignature(signature);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(MESSAGE_BODY))
.withOptions(options);
@ -183,7 +183,7 @@ public class CleartextSignatureVerificationTest {
String signed = signedOut.toString();
ByteArrayInputStream signedIn = new ByteArrayInputStream(signed.getBytes(StandardCharsets.UTF_8));
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
DecryptionStream verificationStream = api.processMessage()
.onInputStream(signedIn)
.withOptions(ConsumerOptions.get(api)
.addVerificationCert(TestKeys.getEmilCertificate()));
@ -217,7 +217,7 @@ public class CleartextSignatureVerificationTest {
String cleartextSigned = out.toString();
ByteArrayInputStream in = new ByteArrayInputStream(cleartextSigned.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addVerificationCert(secretKeys.toCertificate()));

View file

@ -68,7 +68,7 @@ public class CustomPublicKeyDataDecryptorFactoryTest {
};
// Decrypt
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(ciphertextOut.toByteArray()))
.withOptions(ConsumerOptions.get()
.addCustomDecryptorFactory(

View file

@ -56,7 +56,7 @@ public class DecryptAndVerifyMessageTest {
.addDecryptionKey(juliet)
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(juliet));
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes()))
.withOptions(options);
@ -91,7 +91,7 @@ public class DecryptAndVerifyMessageTest {
.addDecryptionKey(juliet)
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(juliet));
try (DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
try (DecryptionStream decryptor = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes()))
.withOptions(options);
ByteArrayOutputStream toPlain = new ByteArrayOutputStream()) {
@ -109,7 +109,7 @@ public class DecryptAndVerifyMessageTest {
.addDecryptionKey(juliet)
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(juliet));
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes()))
.withOptions(options);
@ -150,7 +150,7 @@ public class DecryptAndVerifyMessageTest {
"-----END PGP MESSAGE-----";
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(ciphertext.getBytes());
assertThrows(MissingDecryptionMethodException.class,
() -> PGPainless.decryptAndOrVerify()
() -> PGPainless.getInstance().processMessage()
.onInputStream(ciphertextIn)
.withOptions(ConsumerOptions.get()
.addMessagePassphrase(Passphrase.fromPassword("sw0rdf1sh"))));

View file

@ -131,7 +131,7 @@ public class DecryptHiddenRecipientMessageTest {
ConsumerOptions options = ConsumerOptions.get()
.addDecryptionKey(secretKeys);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(messageIn)
.withOptions(options);

View file

@ -176,7 +176,7 @@ public class IgnoreUnknownSignatureVersionsTest {
}
private MessageMetadata verifySignature(PGPPublicKeyRing cert, String BASE_CASE) throws PGPException, IOException {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify().onInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)))
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage().onInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get()
.addVerificationCert(cert)
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(BASE_CASE.getBytes(StandardCharsets.UTF_8))));

View file

@ -77,7 +77,7 @@ public class MissingPassphraseForDecryptionTest {
.setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy.INTERACTIVE)
.addDecryptionKey(secretKeys, SecretKeyRingProtector.defaultSecretKeyRingProtector(callback));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(message))
.withOptions(options);
@ -112,7 +112,7 @@ public class MissingPassphraseForDecryptionTest {
.addDecryptionKey(secretKeys, SecretKeyRingProtector.defaultSecretKeyRingProtector(callback));
try {
PGPainless.decryptAndOrVerify()
api.processMessage()
.onInputStream(new ByteArrayInputStream(message))
.withOptions(options);
fail("Expected exception!");

View file

@ -215,7 +215,7 @@ public class ModificationDetectionTests {
PGPSecretKeyRingCollection secretKeyRings = getDecryptionKey();
InputStream in = new ByteArrayInputStream(MESSAGE_MISSING_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(secretKeyRings, SecretKeyRingProtector.unprotectedKeys())
@ -232,7 +232,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testTamperedCiphertextThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -249,7 +249,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testIgnoreTamperedCiphertext() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -265,7 +265,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testTamperedMDCThrowsByDefault() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -282,7 +282,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testIgnoreTamperedMDC() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -297,7 +297,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testTruncatedMDCThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TRUNCATED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -311,7 +311,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testMDCWithBadCTBThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -328,7 +328,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testIgnoreMDCWithBadCTB() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -344,7 +344,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testMDCWithBadLengthThrows() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -361,7 +361,7 @@ public class ModificationDetectionTests {
@ExtendWith(TestAllImplementations.class)
public void testIgnoreMDCWithBadLength() throws IOException, PGPException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
@ -532,13 +532,13 @@ public class ModificationDetectionTests {
"-----END PGP MESSAGE-----\n" +
"\n";
assertThrows(MessageNotIntegrityProtectedException.class, () -> PGPainless.decryptAndOrVerify()
assertThrows(MessageNotIntegrityProtectedException.class, () -> PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ciphertext.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeyRing,
SecretKeyRingProtector.unlockAnyKeyWith(passphrase)))
);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ciphertext.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeyRing,
SecretKeyRingProtector.unlockAnyKeyWith(passphrase))

View file

@ -135,7 +135,7 @@ public class PostponeDecryptionUsingKeyWithMissingPassphraseTest {
});
SecretKeyRingProtector protector2 = SecretKeyRingProtector.unlockEachKeyWith(p2, k2);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ENCRYPTED_FOR_K1_K2.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get()
.addDecryptionKey(k1, protector1)
@ -164,7 +164,7 @@ public class PostponeDecryptionUsingKeyWithMissingPassphraseTest {
}
});
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ENCRYPTED_FOR_K1_K2.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get()
.addDecryptionKey(k1, protector1)
@ -193,7 +193,7 @@ public class PostponeDecryptionUsingKeyWithMissingPassphraseTest {
};
SecretKeyRingProtector protector = new CachingSecretKeyRingProtector(provider);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ENCRYPTED_FOR_K2_PASS_K1.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get()
.addMessagePassphrase(PASSPHRASE)

View file

@ -177,7 +177,7 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(ENCRYPTION_CAPABLE_KEY);
ByteArrayInputStream msgIn = new ByteArrayInputStream(MSG.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(msgIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys));
@ -193,7 +193,7 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(ENCRYPTION_INCAPABLE_KEY);
ByteArrayInputStream msgIn = new ByteArrayInputStream(MSG.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(msgIn)
.withOptions(ConsumerOptions.get()
.setAllowDecryptionWithMissingKeyFlags()
@ -213,7 +213,7 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
ByteArrayInputStream msgIn = new ByteArrayInputStream(MSG.getBytes(StandardCharsets.UTF_8));
assertThrows(MissingDecryptionMethodException.class, () ->
PGPainless.decryptAndOrVerify()
PGPainless.getInstance().processMessage()
.onInputStream(msgIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys)));
}
@ -224,7 +224,7 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
ByteArrayInputStream msgIn = new ByteArrayInputStream(MSG.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(msgIn)
.withOptions(ConsumerOptions.get()
.setAllowDecryptionWithMissingKeyFlags()

View file

@ -144,7 +144,7 @@ public class RecursionDepthTest {
assertThrows(MalformedOpenPgpMessageException.class, () -> {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKey));

View file

@ -138,7 +138,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
assertThrows(UnacceptableAlgorithmException.class, () ->
PGPainless.decryptAndOrVerify()
PGPainless.getInstance().processMessage()
.onInputStream(messageIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys))
);
@ -166,7 +166,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
assertThrows(UnacceptableAlgorithmException.class, () ->
PGPainless.decryptAndOrVerify()
PGPainless.getInstance().processMessage()
.onInputStream(messageIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys))
);
@ -193,7 +193,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
assertThrows(UnacceptableAlgorithmException.class, () ->
PGPainless.decryptAndOrVerify().onInputStream(messageIn)
PGPainless.getInstance().processMessage().onInputStream(messageIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys))
);
}
@ -218,7 +218,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
"-----END PGP ARMORED FILE-----\n";
InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
PGPainless.decryptAndOrVerify().onInputStream(messageIn)
PGPainless.getInstance().processMessage().onInputStream(messageIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys));
}

View file

@ -31,7 +31,7 @@ public class SignedMessageVerificationWithoutCertIsStillSignedTest {
@Test
public void verifyMissingVerificationCertOptionStillResultsInMessageIsSigned() throws IOException, PGPException {
ConsumerOptions withoutVerificationCert = ConsumerOptions.get();
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
DecryptionStream verificationStream = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)))
.withOptions(withoutVerificationCert);

View file

@ -44,7 +44,7 @@ public class TestDecryptionOfMessageWithoutESKUsingSessionKey {
@Test
public void decryptMessageWithSKESK() throws PGPException, IOException {
ByteArrayInputStream in = new ByteArrayInputStream(encryptedMessageWithSKESK.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.setSessionKey(sessionKey));
@ -57,7 +57,7 @@ public class TestDecryptionOfMessageWithoutESKUsingSessionKey {
@Test
public void decryptMessageWithoutSKESK() throws PGPException, IOException {
ByteArrayInputStream in = new ByteArrayInputStream(encryptedMessageWithoutESK.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.setSessionKey(sessionKey));

View file

@ -46,7 +46,7 @@ public class TryDecryptWithUnavailableGnuDummyKeyTest {
.removePrivateKeys(GnuPGDummyKeyUtil.KeyFilter.any()));
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(ciphertextOut.toByteArray());
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()
assertThrows(MissingDecryptionMethodException.class, () -> api.processMessage()
.onInputStream(ciphertextIn)
.withOptions(ConsumerOptions.get(api).addDecryptionKey(removedKeys)));
}

View file

@ -392,7 +392,7 @@ public class UnsupportedPacketVersionsTest {
public void decryptAndCompare(String msg, String plain) throws IOException, PGPException {
// noinspection CharsetObjectCanBeUsed
ByteArrayInputStream inputStream = new ByteArrayInputStream(msg.getBytes(Charset.forName("UTF8")));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(inputStream)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(key)

View file

@ -54,7 +54,7 @@ public class VerifyDetachedSignatureTest {
"-----END PGP PUBLIC KEY BLOCK-----\n";
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(signedContent.getBytes(StandardCharsets.UTF_8)))
.withOptions(
ConsumerOptions.get()
@ -129,7 +129,7 @@ public class VerifyDetachedSignatureTest {
"=pXF6\n" +
"-----END PGP PUBLIC KEY BLOCK-----\n";
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(signedContent.getBytes(StandardCharsets.UTF_8)))
.withOptions(
ConsumerOptions.get()

View file

@ -64,7 +64,7 @@ public class VerifyNotBeforeNotAfterTest {
public void noConstraintsVerifyInlineSig() throws PGPException, IOException {
ConsumerOptions options = ConsumerOptions.get()
.addVerificationCert(certificate);
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(inlineSigned))
.withOptions(options);
@ -77,7 +77,7 @@ public class VerifyNotBeforeNotAfterTest {
ConsumerOptions options = ConsumerOptions.get()
.addVerificationCert(certificate)
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(detachedSignature));
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(data))
.withOptions(options);
@ -90,7 +90,7 @@ public class VerifyNotBeforeNotAfterTest {
ConsumerOptions options = ConsumerOptions.get()
.verifyNotBefore(T1)
.addVerificationCert(certificate);
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(inlineSigned))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);
@ -103,7 +103,7 @@ public class VerifyNotBeforeNotAfterTest {
.verifyNotBefore(T1)
.addVerificationCert(certificate)
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(detachedSignature));
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(data))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);
@ -115,7 +115,7 @@ public class VerifyNotBeforeNotAfterTest {
ConsumerOptions options = ConsumerOptions.get()
.verifyNotBefore(T2)
.addVerificationCert(certificate);
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(inlineSigned))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);
@ -128,7 +128,7 @@ public class VerifyNotBeforeNotAfterTest {
.verifyNotBefore(T2)
.addVerificationCert(certificate)
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(detachedSignature));
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(data))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);
@ -140,7 +140,7 @@ public class VerifyNotBeforeNotAfterTest {
ConsumerOptions options = ConsumerOptions.get()
.verifyNotAfter(T1)
.addVerificationCert(certificate);
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(inlineSigned))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);
@ -153,7 +153,7 @@ public class VerifyNotBeforeNotAfterTest {
.verifyNotAfter(T1)
.addVerificationCert(certificate)
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(detachedSignature));
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(data))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);
@ -165,7 +165,7 @@ public class VerifyNotBeforeNotAfterTest {
ConsumerOptions options = ConsumerOptions.get()
.verifyNotAfter(T0)
.addVerificationCert(certificate);
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(inlineSigned))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);
@ -178,7 +178,7 @@ public class VerifyNotBeforeNotAfterTest {
.verifyNotAfter(T0)
.addVerificationCert(certificate)
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(detachedSignature));
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(data))
.withOptions(options);
MessageMetadata metadata = processSignedData(verifier);

View file

@ -213,7 +213,7 @@ public class VerifySignatureByCertificationKeyFailsTest {
public void testSignatureByNonSigningPrimaryKeyIsRejected() throws Exception {
PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(KEY);
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(DATA))
.withOptions(ConsumerOptions.get()
.addVerificationCert(PGPainless.extractCertificate(key))

View file

@ -39,7 +39,7 @@ class VerifyVersion3SignaturePacketTest {
.addVerificationCert(TestKeys.getEmilPublicKeyRing())
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(version3Signature.getEncoded()));
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(DATA))
.withOptions(options);

View file

@ -52,7 +52,7 @@ public class VerifyWithMissingPublicKeyCallbackTest {
String msg = "Arguing that you don't care about the right to privacy because you have nothing to hide" +
"is no different than saying you don't care about free speech because you have nothing to say.";
ByteArrayOutputStream signOut = new ByteArrayOutputStream();
EncryptionStream signingStream = PGPainless.encryptAndOrSign().onOutputStream(signOut)
EncryptionStream signingStream = api.generateMessage().onOutputStream(signOut)
.withOptions(ProducerOptions.sign(SigningOptions.get().addInlineSignature(
SecretKeyRingProtector.unprotectedKeys(),
signingSecKeys.getPGPSecretKeyRing(), DocumentSignatureType.CANONICAL_TEXT_DOCUMENT
@ -60,7 +60,7 @@ public class VerifyWithMissingPublicKeyCallbackTest {
Streams.pipeAll(new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)), signingStream);
signingStream.close();
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
DecryptionStream verificationStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(signOut.toByteArray()))
.withOptions(ConsumerOptions.get()
.addVerificationCert(unrelatedKeys)

View file

@ -96,7 +96,7 @@ public class BcHashContextSignerTest {
OpenPGPSignature.OpenPGPDocumentSignature signature = signMessage(messageBytes, hashAlgorithm, secretKeys);
assertEquals(hashAlgorithm.getAlgorithmId(), signature.getSignature().getHashAlgorithm());
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(messageIn)
.withOptions(ConsumerOptions.get()
.addVerificationCert(certificate)

View file

@ -157,7 +157,7 @@ public class EncryptDecryptTest {
// Juliet trieth to comprehend Romeos words
ByteArrayInputStream envelopeIn = new ByteArrayInputStream(encryptedSecretMessage);
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = api.processMessage()
.onInputStream(envelopeIn)
.withOptions(ConsumerOptions.get(api)
.addDecryptionKey(recipientSec, keyDecryptor)
@ -208,7 +208,7 @@ public class EncryptDecryptTest {
// CHECKSTYLE:ON
inputStream = new ByteArrayInputStream(testMessage.getBytes());
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = api.processMessage()
.onInputStream(inputStream)
.withOptions(ConsumerOptions.get(api)
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(armorSig.getBytes()))
@ -241,7 +241,7 @@ public class EncryptDecryptTest {
signer.close();
inputStream = new ByteArrayInputStream(signOut.toByteArray());
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
DecryptionStream verifier = api.processMessage()
.onInputStream(inputStream)
.withOptions(ConsumerOptions.get(api)
.addVerificationCert(signingKeys.toCertificate())
@ -349,7 +349,7 @@ public class EncryptDecryptTest {
result.getEncryptionMechanism());
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
DecryptionStream decIn = PGPainless.decryptAndOrVerify()
DecryptionStream decIn = api.processMessage()
.onInputStream(bIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(keyWithoutSEIPD2Feature));
@ -387,7 +387,7 @@ public class EncryptDecryptTest {
result.getEncryptionMechanism());
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
DecryptionStream decIn = PGPainless.decryptAndOrVerify()
DecryptionStream decIn = api.processMessage()
.onInputStream(bIn)
.withOptions(ConsumerOptions.get()
.addMessagePassphrase(Passphrase.fromPassword("sw0rdf1sh")));

View file

@ -164,7 +164,7 @@ public class EncryptionWithMissingKeyFlagsTest {
// Prepare encryption
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream encOut = PGPainless.encryptAndOrSign()
EncryptionStream encOut = PGPainless.getInstance().generateMessage()
.onOutputStream(out)
.withOptions(ProducerOptions.encrypt(EncryptionOptions.get()
.setEvaluationDate(evaluationDate)
@ -177,7 +177,7 @@ public class EncryptionWithMissingKeyFlagsTest {
// Prepare decryption
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.setAllowDecryptionWithMissingKeyFlags()

View file

@ -73,7 +73,7 @@ public class FileInformationTest {
ByteArrayInputStream cryptIn = new ByteArrayInputStream(dataOut.toByteArray());
ByteArrayOutputStream plainOut = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(cryptIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKey));
@ -112,7 +112,7 @@ public class FileInformationTest {
ByteArrayInputStream cryptIn = new ByteArrayInputStream(dataOut.toByteArray());
ByteArrayOutputStream plainOut = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(cryptIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKey));
@ -156,7 +156,7 @@ public class FileInformationTest {
ByteArrayInputStream cryptIn = new ByteArrayInputStream(dataOut.toByteArray());
ByteArrayOutputStream plainOut = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(cryptIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKey));

View file

@ -52,7 +52,7 @@ public class HiddenRecipientEncryptionTest {
byte[] ciphertext = ciphertextOut.toByteArray();
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(ciphertext);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(ciphertextIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys));

View file

@ -128,7 +128,7 @@ public class MechanismNegotiationTest {
eOut.close();
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
DecryptionStream dIn = PGPainless.decryptAndOrVerify()
DecryptionStream dIn = api.processMessage()
.onInputStream(bIn)
.withOptions(ConsumerOptions.get().addDecryptionKey(keyList.get(0)));

View file

@ -49,7 +49,8 @@ public class MultiSigningSubkeyTest {
@BeforeAll
public static void generateKey() {
signingKey = PGPainless.buildKeyRing()
PGPainless api = PGPainless.getInstance();
signingKey = api.buildKey()
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
.addSubkey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA))
.addSubkey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072), KeyFlag.SIGN_DATA))
@ -69,7 +70,7 @@ public class MultiSigningSubkeyTest {
public void detachedSignWithAllSubkeys() throws PGPException, IOException {
ByteArrayInputStream dataIn = new ByteArrayInputStream("Hello, World!\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream signingStream = PGPainless.encryptAndOrSign()
EncryptionStream signingStream = PGPainless.getInstance().generateMessage()
.onOutputStream(out)
.withOptions(ProducerOptions.sign(SigningOptions.get().addDetachedSignature(protector, signingKey, DocumentSignatureType.BINARY_DOCUMENT)));
Streams.pipeAll(dataIn, signingStream);
@ -85,7 +86,7 @@ public class MultiSigningSubkeyTest {
public void detachedSignWithSingleSubkey() throws PGPException, IOException {
ByteArrayInputStream dataIn = new ByteArrayInputStream("Hello, World!\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream signingStream = PGPainless.encryptAndOrSign()
EncryptionStream signingStream = PGPainless.getInstance().generateMessage()
.onOutputStream(out)
.withOptions(ProducerOptions.sign(SigningOptions.get().addDetachedSignature(protector, signingKey, signingKey1.getKeyId())));
Streams.pipeAll(dataIn, signingStream);
@ -98,16 +99,17 @@ public class MultiSigningSubkeyTest {
@Test
public void inlineSignWithAllSubkeys() throws PGPException, IOException {
PGPainless api = PGPainless.getInstance();
ByteArrayInputStream dataIn = new ByteArrayInputStream("Hello, World!\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream signingStream = PGPainless.encryptAndOrSign()
EncryptionStream signingStream = api.generateMessage()
.onOutputStream(out)
.withOptions(ProducerOptions.sign(SigningOptions.get().addInlineSignature(protector, signingKey, DocumentSignatureType.BINARY_DOCUMENT)));
Streams.pipeAll(dataIn, signingStream);
signingStream.close();
ByteArrayInputStream signedIn = new ByteArrayInputStream(out.toByteArray());
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify().onInputStream(signedIn)
DecryptionStream verificationStream = api.processMessage().onInputStream(signedIn)
.withOptions(ConsumerOptions.get().addVerificationCert(signingCert));
Streams.drain(verificationStream);
verificationStream.close();
@ -122,16 +124,17 @@ public class MultiSigningSubkeyTest {
@Test
public void inlineSignWithSingleSubkey() throws PGPException, IOException {
PGPainless api = PGPainless.getInstance();
ByteArrayInputStream dataIn = new ByteArrayInputStream("Hello, World!\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream signingStream = PGPainless.encryptAndOrSign()
EncryptionStream signingStream = api.generateMessage()
.onOutputStream(out)
.withOptions(ProducerOptions.sign(SigningOptions.get().addInlineSignature(protector, signingKey, signingKey1.getKeyId())));
Streams.pipeAll(dataIn, signingStream);
signingStream.close();
ByteArrayInputStream signedIn = new ByteArrayInputStream(out.toByteArray());
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify().onInputStream(signedIn)
DecryptionStream verificationStream = api.processMessage().onInputStream(signedIn)
.withOptions(ConsumerOptions.get().addVerificationCert(signingCert));
Streams.drain(verificationStream);
verificationStream.close();

View file

@ -82,7 +82,7 @@ public class SigningTest {
OpenPGPKey romeoKey = TestKeys.getRomeoKey();
OpenPGPKey julietKey = TestKeys.getJulietKey();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(cryptIn)
.withOptions(ConsumerOptions.get(api)
.addDecryptionKey(romeoKey, SecretKeyRingProtector.unprotectedKeys())

View file

@ -159,7 +159,7 @@ public class DecryptOrVerify {
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(ENCRYPTED.getBytes(StandardCharsets.UTF_8));
// The decryption stream is an input stream from which we read the decrypted data
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(ciphertextIn)
.withOptions(consumerOptions);
@ -189,7 +189,7 @@ public class DecryptOrVerify {
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(ENCRYPTED_AND_SIGNED.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(ciphertextIn)
.withOptions(consumerOptions);
@ -219,7 +219,7 @@ public class DecryptOrVerify {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(signed.getBytes(StandardCharsets.UTF_8));
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
DecryptionStream verificationStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(options);
@ -270,7 +270,7 @@ public class DecryptOrVerify {
ByteArrayInputStream signedIn = new ByteArrayInputStream(signedMessage);
// and pass it to the decryption stream
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
DecryptionStream verificationStream = api.processMessage()
.onInputStream(signedIn)
.withOptions(ConsumerOptions.get(api).addVerificationCert(certificate));

View file

@ -166,7 +166,7 @@ public class Encrypt {
String encryptedMessage = ciphertext.toString();
// Decrypt and verify signatures
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = api.processMessage()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get(api)
.addDecryptionKey(keyBob, protectorBob)
@ -209,7 +209,7 @@ public class Encrypt {
String asciiCiphertext = ciphertext.toString();
// Decrypt
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = api.processMessage()
.onInputStream(new ByteArrayInputStream(asciiCiphertext.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get(api).addMessagePassphrase(Passphrase.fromPassword("p4ssphr4s3")));
@ -274,7 +274,7 @@ public class Encrypt {
// also test, that decryption still works...
// Decrypt and verify signatures
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = api.processMessage()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get(api)
.addDecryptionKey(keyBob, protectorBob)

View file

@ -77,7 +77,7 @@ public class GenerateKeyWithoutPrimaryKeyFlagsTest {
EncryptionResult result = encryptionStream.getResult();
assertTrue(result.isEncryptedFor(cert));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(ciphertext.toByteArray()))
.withOptions(ConsumerOptions.get().addDecryptionKey(key)
.addVerificationCert(cert));

View file

@ -78,7 +78,7 @@ public class GenerateKeyWithoutUserIdTest {
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(ciphertextOut.toByteArray());
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(ciphertextIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKey)

View file

@ -160,7 +160,7 @@ public class FixUserIdDoesNotBreakEncryptionCapabilityTest {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ByteArrayOutputStream plain = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(edited));

View file

@ -111,7 +111,7 @@ public class S2KUsageFixTest {
private void testCanStillDecrypt(OpenPGPKey keys, SecretKeyRingProtector protector)
throws PGPException, IOException {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(in)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(keys, protector));

View file

@ -185,7 +185,7 @@ public class WeakRSAKeyTest {
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(encryptOut.toByteArray());
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(ciphertextIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys));

View file

@ -1970,7 +1970,7 @@ public class BindingSignatureSubpacketsTest {
PGPainless api = PGPainless.getInstance();
OpenPGPCertificate certificate = api.readKey().parseCertificate(key);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify().onInputStream(getSignedData(data))
DecryptionStream decryptionStream = api.processMessage().onInputStream(getSignedData(data))
.withOptions(ConsumerOptions.get(api)
.addVerificationCert(certificate)
.addVerificationOfDetachedSignatures(SignatureUtils.readSignatures(sig)));
@ -1990,7 +1990,7 @@ public class BindingSignatureSubpacketsTest {
PGPainless api = PGPainless.getInstance();
OpenPGPCertificate certificate = api.readKey().parseCertificate(key);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify().onInputStream(getSignedData(data))
DecryptionStream decryptionStream = api.processMessage().onInputStream(getSignedData(data))
.withOptions(ConsumerOptions.get(api)
.addVerificationCert(certificate)
.addVerificationOfDetachedSignatures(SignatureUtils.readSignatures(sig)));

View file

@ -1305,7 +1305,7 @@ public class CertificateValidatorTest {
PGPainless api = PGPainless.getInstance();
OpenPGPCertificate certificate = api.toCertificate(cert);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(dataIn)
.withOptions(ConsumerOptions.get(api)
.addVerificationOfDetachedSignature(signature)
@ -1385,11 +1385,12 @@ public class CertificateValidatorTest {
"=NXei\n" +
"-----END PGP PUBLIC KEY BLOCK-----\n";
String DATA = "Hello World :)";
PGPainless api = PGPainless.getInstance();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(new ByteArrayInputStream(DATA.getBytes(StandardCharsets.UTF_8)))
.withOptions(ConsumerOptions.get()
.addVerificationCert(PGPainless.readKeyRing().publicKeyRing(CERT))
.addVerificationCert(api.readKey().parseCertificate(CERT))
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(SIG.getBytes(StandardCharsets.UTF_8))));
Streams.drain(decryptionStream);

View file

@ -142,7 +142,7 @@ public class IgnoreMarkerPacketsTest {
PGPSignature signature = SignatureUtils.readSignatures(sig).get(0);
InputStream messageIn = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(messageIn)
.withOptions(ConsumerOptions.get()
.addVerificationCert(publicKeys)
@ -191,7 +191,7 @@ public class IgnoreMarkerPacketsTest {
String data = "Marker + Encrypted Message";
InputStream messageIn = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = PGPainless.getInstance().processMessage()
.onInputStream(messageIn)
.withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys)

View file

@ -269,7 +269,7 @@ public class KeyRevocationTest {
private void verify(PGPSignature signature, InputStream dataIn, OpenPGPCertificate certificate, PGPainless api)
throws PGPException, IOException {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
DecryptionStream decryptionStream = api.processMessage()
.onInputStream(dataIn)
.withOptions(ConsumerOptions.get(api)
.addVerificationOfDetachedSignature(signature)

View file

@ -31,7 +31,7 @@ public class MultiPassphraseSymmetricEncryptionTest {
"the decryptor finds the session key encrypted for the right passphrase.";
ByteArrayInputStream plaintextIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream ciphertextOut = new ByteArrayOutputStream();
EncryptionStream encryptor = PGPainless.encryptAndOrSign()
EncryptionStream encryptor = PGPainless.getInstance().generateMessage()
.onOutputStream(ciphertextOut)
.withOptions(ProducerOptions.encrypt(
EncryptionOptions.encryptCommunications()
@ -46,7 +46,7 @@ public class MultiPassphraseSymmetricEncryptionTest {
// decrypting the p1 package with p2 first will not work. Test if it is handled correctly.
for (Passphrase passphrase : new Passphrase[] {Passphrase.fromPassword("p2"), Passphrase.fromPassword("p1")}) {
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ciphertext))
.withOptions(ConsumerOptions.get()
.addMessagePassphrase(passphrase));

View file

@ -63,7 +63,7 @@ public class SymmetricEncryptionTest {
byte[] ciphertext = ciphertextOut.toByteArray();
// Test symmetric decryption
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
DecryptionStream decryptor = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ciphertext))
.withOptions(ConsumerOptions.get()
.addMessagePassphrase(encryptionPassphrase));
@ -80,7 +80,7 @@ public class SymmetricEncryptionTest {
SecretKeyRingProtector protector = new PasswordBasedSecretKeyRingProtector(
KeyRingProtectionSettings.secureDefaultSettings(),
new SolitaryPassphraseProvider(Passphrase.fromPassword(TestKeys.CRYPTIE_PASSWORD)));
decryptor = PGPainless.decryptAndOrVerify()
decryptor = PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ciphertext))
.withOptions(ConsumerOptions.get()
.addDecryptionKeys(decryptionKeys, protector));
@ -100,7 +100,7 @@ public class SymmetricEncryptionTest {
new Random().nextBytes(bytes);
ByteArrayOutputStream ciphertextOut = new ByteArrayOutputStream();
EncryptionStream encryptor = PGPainless.encryptAndOrSign().onOutputStream(ciphertextOut)
EncryptionStream encryptor = PGPainless.getInstance().generateMessage().onOutputStream(ciphertextOut)
.withOptions(ProducerOptions.encrypt(
EncryptionOptions.encryptCommunications()
.addMessagePassphrase(Passphrase.fromPassword("mellon"))));
@ -108,7 +108,7 @@ public class SymmetricEncryptionTest {
Streams.pipeAll(new ByteArrayInputStream(bytes), encryptor);
encryptor.close();
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.getInstance().processMessage()
.onInputStream(new ByteArrayInputStream(ciphertextOut.toByteArray()))
.withOptions(ConsumerOptions.get()
.setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy.THROW_EXCEPTION)

View file

@ -39,9 +39,7 @@ class DecryptImpl(private val api: PGPainless) : Decrypt {
val decryptionStream =
try {
PGPainless.decryptAndOrVerify()
.onInputStream(ciphertext)
.withOptions(consumerOptions)
api.processMessage().onInputStream(ciphertext).withOptions(consumerOptions)
} catch (e: MissingDecryptionMethodException) {
throw SOPGPException.CannotDecrypt(
"No usable decryption key or password provided.", e)

View file

@ -28,8 +28,7 @@ class DetachedVerifyImpl(private val api: PGPainless) : DetachedVerify {
override fun data(data: InputStream): List<Verification> {
try {
val verificationStream =
PGPainless.decryptAndOrVerify().onInputStream(data).withOptions(options)
val verificationStream = api.processMessage().onInputStream(data).withOptions(options)
Streams.drain(verificationStream)
verificationStream.close()

View file

@ -32,7 +32,7 @@ class InlineVerifyImpl(private val api: PGPainless) : InlineVerify {
override fun writeTo(outputStream: OutputStream): List<Verification> {
try {
val verificationStream =
PGPainless.decryptAndOrVerify().onInputStream(data).withOptions(options)
api.processMessage().onInputStream(data).withOptions(options)
Streams.pipeAll(verificationStream, outputStream)
verificationStream.close()