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

Move default parameters of Options classes to factory methods

This commit is contained in:
Paul Schaub 2025-03-18 14:24:49 +01:00
parent 2489237071
commit 3ea51f77be
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
26 changed files with 117 additions and 92 deletions

View file

@ -24,7 +24,7 @@ import org.pgpainless.util.Passphrase
import org.pgpainless.util.SessionKey import org.pgpainless.util.SessionKey
/** Options for decryption and signature verification. */ /** Options for decryption and signature verification. */
class ConsumerOptions(private val api: PGPainless = PGPainless.getInstance()) { class ConsumerOptions(private val api: PGPainless) {
private var ignoreMDCErrors = false private var ignoreMDCErrors = false
var isDisableAsciiArmorCRC = false var isDisableAsciiArmorCRC = false
@ -468,6 +468,8 @@ class ConsumerOptions(private val api: PGPainless = PGPainless.getInstance()) {
} }
companion object { companion object {
@JvmStatic fun get() = ConsumerOptions() @JvmOverloads
@JvmStatic
fun get(api: PGPainless = PGPainless.getInstance()) = ConsumerOptions(api)
} }
} }

View file

@ -22,10 +22,7 @@ import org.pgpainless.key.info.KeyAccessor
import org.pgpainless.key.info.KeyRingInfo import org.pgpainless.key.info.KeyRingInfo
import org.pgpainless.util.Passphrase import org.pgpainless.util.Passphrase
class EncryptionOptions( class EncryptionOptions(private val purpose: EncryptionPurpose, private val api: PGPainless) {
private val purpose: EncryptionPurpose,
private val api: PGPainless = PGPainless.getInstance()
) {
private val _encryptionMethods: MutableSet<PGPKeyEncryptionMethodGenerator> = mutableSetOf() private val _encryptionMethods: MutableSet<PGPKeyEncryptionMethodGenerator> = mutableSetOf()
private val _encryptionKeys: MutableSet<OpenPGPComponentKey> = mutableSetOf() private val _encryptionKeys: MutableSet<OpenPGPComponentKey> = mutableSetOf()
private val _encryptionKeyIdentifiers: MutableSet<SubkeyIdentifier> = mutableSetOf() private val _encryptionKeyIdentifiers: MutableSet<SubkeyIdentifier> = mutableSetOf()
@ -55,7 +52,7 @@ class EncryptionOptions(
val encryptionAlgorithmOverride val encryptionAlgorithmOverride
get() = _encryptionAlgorithmOverride get() = _encryptionAlgorithmOverride
constructor() : this(EncryptionPurpose.ANY) constructor(api: PGPainless) : this(EncryptionPurpose.ANY, api)
/** /**
* Set the evaluation date for certificate evaluation. * Set the evaluation date for certificate evaluation.
@ -426,11 +423,19 @@ class EncryptionOptions(
} }
companion object { companion object {
@JvmStatic fun get() = EncryptionOptions() @JvmOverloads
@JvmStatic
fun get(api: PGPainless = PGPainless.getInstance()) = EncryptionOptions(api)
@JvmStatic fun encryptCommunications() = EncryptionOptions(EncryptionPurpose.COMMUNICATIONS) @JvmOverloads
@JvmStatic
fun encryptCommunications(api: PGPainless = PGPainless.getInstance()) =
EncryptionOptions(EncryptionPurpose.COMMUNICATIONS, api)
@JvmStatic fun encryptDataAtRest() = EncryptionOptions(EncryptionPurpose.STORAGE) @JvmOverloads
@JvmStatic
fun encryptDataAtRest(api: PGPainless = PGPainless.getInstance()) =
EncryptionOptions(EncryptionPurpose.STORAGE, api)
/** /**
* Only encrypt to the first valid encryption capable subkey we stumble upon. * Only encrypt to the first valid encryption capable subkey we stumble upon.

View file

@ -13,7 +13,7 @@ import org.pgpainless.algorithm.StreamEncoding
class ProducerOptions( class ProducerOptions(
val encryptionOptions: EncryptionOptions?, val encryptionOptions: EncryptionOptions?,
val signingOptions: SigningOptions?, val signingOptions: SigningOptions?,
val api: PGPainless = PGPainless.getInstance() val api: PGPainless
) { ) {
private var _fileName: String = "" private var _fileName: String = ""
@ -249,9 +249,13 @@ class ProducerOptions(
* @param signingOptions signing options * @param signingOptions signing options
* @return builder * @return builder
*/ */
@JvmOverloads
@JvmStatic @JvmStatic
fun signAndEncrypt(encryptionOptions: EncryptionOptions, signingOptions: SigningOptions) = fun signAndEncrypt(
ProducerOptions(encryptionOptions, signingOptions) encryptionOptions: EncryptionOptions,
signingOptions: SigningOptions,
api: PGPainless = PGPainless.getInstance()
): ProducerOptions = ProducerOptions(encryptionOptions, signingOptions, api)
/** /**
* Sign some data without encryption. * Sign some data without encryption.
@ -259,7 +263,12 @@ class ProducerOptions(
* @param signingOptions signing options * @param signingOptions signing options
* @return builder * @return builder
*/ */
@JvmStatic fun sign(signingOptions: SigningOptions) = ProducerOptions(null, signingOptions) @JvmOverloads
@JvmStatic
fun sign(
signingOptions: SigningOptions,
api: PGPainless = PGPainless.getInstance()
): ProducerOptions = ProducerOptions(null, signingOptions, api)
/** /**
* Encrypt some data without signing. * Encrypt some data without signing.
@ -267,14 +276,21 @@ class ProducerOptions(
* @param encryptionOptions encryption options * @param encryptionOptions encryption options
* @return builder * @return builder
*/ */
@JvmOverloads
@JvmStatic @JvmStatic
fun encrypt(encryptionOptions: EncryptionOptions) = ProducerOptions(encryptionOptions, null) fun encrypt(
encryptionOptions: EncryptionOptions,
api: PGPainless = PGPainless.getInstance()
): ProducerOptions = ProducerOptions(encryptionOptions, null, api)
/** /**
* Only wrap the data in an OpenPGP packet. No encryption or signing will be applied. * Only wrap the data in an OpenPGP packet. No encryption or signing will be applied.
* *
* @return builder * @return builder
*/ */
@JvmStatic fun noEncryptionNoSigning() = ProducerOptions(null, null) @JvmOverloads
@JvmStatic
fun noEncryptionNoSigning(api: PGPainless = PGPainless.getInstance()): ProducerOptions =
ProducerOptions(null, null, api)
} }
} }

View file

@ -27,7 +27,7 @@ import org.pgpainless.signature.subpackets.BaseSignatureSubpackets.Callback
import org.pgpainless.signature.subpackets.SignatureSubpackets import org.pgpainless.signature.subpackets.SignatureSubpackets
import org.pgpainless.signature.subpackets.SignatureSubpacketsHelper import org.pgpainless.signature.subpackets.SignatureSubpacketsHelper
class SigningOptions(val api: PGPainless = PGPainless.getInstance()) { class SigningOptions(private val api: PGPainless) {
val signingMethods: Map<OpenPGPPrivateKey, SigningMethod> = mutableMapOf() val signingMethods: Map<OpenPGPPrivateKey, SigningMethod> = mutableMapOf()
private var _hashAlgorithmOverride: HashAlgorithm? = null private var _hashAlgorithmOverride: HashAlgorithm? = null
@ -500,7 +500,9 @@ class SigningOptions(val api: PGPainless = PGPainless.getInstance()) {
} }
companion object { companion object {
@JvmStatic fun get() = SigningOptions() @JvmOverloads
@JvmStatic
fun get(api: PGPainless = PGPainless.getInstance()) = SigningOptions(api)
} }
/** A method of signing. */ /** A method of signing. */

View file

@ -299,7 +299,7 @@ public class CanonicalizedDataEncryptionTest {
ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys())
.addVerificationCert(publicKeys)); .addVerificationCert(publicKeys));
@ -329,7 +329,7 @@ public class CanonicalizedDataEncryptionTest {
ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys())
.addVerificationCert(publicKeys)); .addVerificationCert(publicKeys));
@ -375,7 +375,7 @@ public class CanonicalizedDataEncryptionTest {
ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKey(secretKeys, SecretKeyRingProtector.unprotectedKeys())
.addVerificationCert(publicKeys)); .addVerificationCert(publicKeys));
@ -446,7 +446,7 @@ public class CanonicalizedDataEncryptionTest {
ByteArrayOutputStream decrypted = new ByteArrayOutputStream(); ByteArrayOutputStream decrypted = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(cipherIn) .onInputStream(cipherIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(publicKeys)); .addVerificationCert(publicKeys));
Streams.pipeAll(decryptionStream, decrypted); Streams.pipeAll(decryptionStream, decrypted);

View file

@ -136,7 +136,7 @@ public class CertificateWithMissingSecretKeyTest {
// Test decryption // Test decryption
ByteArrayInputStream cipherIn = new ByteArrayInputStream(out.toByteArray()); ByteArrayInputStream cipherIn = new ByteArrayInputStream(out.toByteArray());
ConsumerOptions consumerOptions = new ConsumerOptions() ConsumerOptions consumerOptions = ConsumerOptions.get()
.addDecryptionKey(missingDecryptionSecKey); .addDecryptionKey(missingDecryptionSecKey);
assertThrows(MissingDecryptionMethodException.class, () -> assertThrows(MissingDecryptionMethodException.class, () ->

View file

@ -81,7 +81,7 @@ public class CleartextSignatureVerificationTest {
public void cleartextSignVerification_InMemoryMultiPassStrategy() public void cleartextSignVerification_InMemoryMultiPassStrategy()
throws IOException, PGPException { throws IOException, PGPException {
PGPPublicKeyRing signingKeys = TestKeys.getEmilPublicKeyRing(); PGPPublicKeyRing signingKeys = TestKeys.getEmilPublicKeyRing();
ConsumerOptions options = new ConsumerOptions() ConsumerOptions options = ConsumerOptions.get()
.addVerificationCert(signingKeys); .addVerificationCert(signingKeys);
InMemoryMultiPassStrategy multiPassStrategy = MultiPassStrategy.keepMessageInMemory(); InMemoryMultiPassStrategy multiPassStrategy = MultiPassStrategy.keepMessageInMemory();
@ -108,7 +108,7 @@ public class CleartextSignatureVerificationTest {
public void cleartextSignVerification_FileBasedMultiPassStrategy() public void cleartextSignVerification_FileBasedMultiPassStrategy()
throws IOException, PGPException { throws IOException, PGPException {
PGPPublicKeyRing signingKeys = TestKeys.getEmilPublicKeyRing(); PGPPublicKeyRing signingKeys = TestKeys.getEmilPublicKeyRing();
ConsumerOptions options = new ConsumerOptions() ConsumerOptions options = ConsumerOptions.get()
.addVerificationCert(signingKeys); .addVerificationCert(signingKeys);
File tempDir = TestUtils.createTempDirectory(); File tempDir = TestUtils.createTempDirectory();
@ -164,7 +164,7 @@ public class CleartextSignatureVerificationTest {
throws IOException, PGPException { throws IOException, PGPException {
PGPSignature signature = SignatureUtils.readSignatures(SIGNATURE).get(0); PGPSignature signature = SignatureUtils.readSignatures(SIGNATURE).get(0);
ConsumerOptions options = new ConsumerOptions() ConsumerOptions options = ConsumerOptions.get()
.addVerificationCert(TestKeys.getEmilPublicKeyRing()) .addVerificationCert(TestKeys.getEmilPublicKeyRing())
.addVerificationOfDetachedSignature(signature); .addVerificationOfDetachedSignature(signature);
@ -201,7 +201,7 @@ public class CleartextSignatureVerificationTest {
ByteArrayInputStream signedIn = new ByteArrayInputStream(signed.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream signedIn = new ByteArrayInputStream(signed.getBytes(StandardCharsets.UTF_8));
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify() DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
.onInputStream(signedIn) .onInputStream(signedIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(TestKeys.getEmilPublicKeyRing())); .addVerificationCert(TestKeys.getEmilPublicKeyRing()));
ByteArrayOutputStream msgOut = new ByteArrayOutputStream(); ByteArrayOutputStream msgOut = new ByteArrayOutputStream();
@ -236,7 +236,7 @@ public class CleartextSignatureVerificationTest {
ByteArrayInputStream in = new ByteArrayInputStream(cleartextSigned.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(cleartextSigned.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(PGPainless.extractCertificate(secretKeys))); .addVerificationCert(PGPainless.extractCertificate(secretKeys)));
out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream();

View file

@ -74,7 +74,7 @@ public class MissingPassphraseForDecryptionTest {
return true; return true;
} }
}; };
ConsumerOptions options = new ConsumerOptions() ConsumerOptions options = ConsumerOptions.get()
.setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy.INTERACTIVE) .setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy.INTERACTIVE)
.addDecryptionKey(secretKeys, SecretKeyRingProtector.defaultSecretKeyRingProtector(callback)); .addDecryptionKey(secretKeys, SecretKeyRingProtector.defaultSecretKeyRingProtector(callback));
@ -108,7 +108,7 @@ public class MissingPassphraseForDecryptionTest {
} }
}; };
ConsumerOptions options = new ConsumerOptions() ConsumerOptions options = ConsumerOptions.get()
.setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy.THROW_EXCEPTION) .setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy.THROW_EXCEPTION)
.addDecryptionKey(secretKeys, SecretKeyRingProtector.defaultSecretKeyRingProtector(callback)); .addDecryptionKey(secretKeys, SecretKeyRingProtector.defaultSecretKeyRingProtector(callback));

View file

@ -217,7 +217,7 @@ public class ModificationDetectionTests {
InputStream in = new ByteArrayInputStream(MESSAGE_MISSING_MDC.getBytes(StandardCharsets.UTF_8)); InputStream in = new ByteArrayInputStream(MESSAGE_MISSING_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(secretKeyRings, SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(secretKeyRings, SecretKeyRingProtector.unprotectedKeys())
); );
@ -234,7 +234,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
); );
@ -251,7 +251,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
.setIgnoreMDCErrors(true) .setIgnoreMDCErrors(true)
); );
@ -267,7 +267,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
); );
@ -284,7 +284,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
.setIgnoreMDCErrors(true) .setIgnoreMDCErrors(true)
); );
@ -299,7 +299,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TRUNCATED_MDC.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TRUNCATED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
); );
@ -313,7 +313,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
); );
@ -330,7 +330,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
.setIgnoreMDCErrors(true) .setIgnoreMDCErrors(true)
); );
@ -346,7 +346,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
); );
@ -363,7 +363,7 @@ public class ModificationDetectionTests {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(getDecryptionKey(), SecretKeyRingProtector.unprotectedKeys())
.setIgnoreMDCErrors(true) .setIgnoreMDCErrors(true)
); );
@ -534,7 +534,7 @@ public class ModificationDetectionTests {
assertThrows(MessageNotIntegrityProtectedException.class, () -> PGPainless.decryptAndOrVerify() assertThrows(MessageNotIntegrityProtectedException.class, () -> PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(ciphertext.getBytes(StandardCharsets.UTF_8))) .onInputStream(new ByteArrayInputStream(ciphertext.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions().addDecryptionKey(secretKeyRing, .withOptions(ConsumerOptions.get().addDecryptionKey(secretKeyRing,
SecretKeyRingProtector.unlockAnyKeyWith(passphrase))) SecretKeyRingProtector.unlockAnyKeyWith(passphrase)))
); );

View file

@ -743,7 +743,7 @@ public class OpenPgpInputStreamTest {
ByteArrayOutputStream signedOut = new ByteArrayOutputStream(); ByteArrayOutputStream signedOut = new ByteArrayOutputStream();
EncryptionStream signer = PGPainless.encryptAndOrSign() EncryptionStream signer = PGPainless.encryptAndOrSign()
.onOutputStream(signedOut) .onOutputStream(signedOut)
.withOptions(ProducerOptions.sign(new SigningOptions() .withOptions(ProducerOptions.sign(SigningOptions.get()
.addSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys)) .addSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys))
.setAsciiArmor(false) .setAsciiArmor(false)
.overrideCompressionAlgorithm(CompressionAlgorithm.UNCOMPRESSED)); .overrideCompressionAlgorithm(CompressionAlgorithm.UNCOMPRESSED));

View file

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

View file

@ -140,7 +140,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
assertThrows(UnacceptableAlgorithmException.class, () -> assertThrows(UnacceptableAlgorithmException.class, () ->
PGPainless.decryptAndOrVerify() PGPainless.decryptAndOrVerify()
.onInputStream(messageIn) .onInputStream(messageIn)
.withOptions(new ConsumerOptions().addDecryptionKey(secretKeys)) .withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys))
); );
} }
@ -168,7 +168,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
assertThrows(UnacceptableAlgorithmException.class, () -> assertThrows(UnacceptableAlgorithmException.class, () ->
PGPainless.decryptAndOrVerify() PGPainless.decryptAndOrVerify()
.onInputStream(messageIn) .onInputStream(messageIn)
.withOptions(new ConsumerOptions().addDecryptionKey(secretKeys)) .withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys))
); );
} }
@ -194,7 +194,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)); InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
assertThrows(UnacceptableAlgorithmException.class, () -> assertThrows(UnacceptableAlgorithmException.class, () ->
PGPainless.decryptAndOrVerify().onInputStream(messageIn) PGPainless.decryptAndOrVerify().onInputStream(messageIn)
.withOptions(new ConsumerOptions().addDecryptionKey(secretKeys)) .withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys))
); );
} }
@ -219,7 +219,7 @@ public class RejectWeakSymmetricAlgorithmDuringDecryptionTest {
InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)); InputStream messageIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));
PGPainless.decryptAndOrVerify().onInputStream(messageIn) PGPainless.decryptAndOrVerify().onInputStream(messageIn)
.withOptions(new ConsumerOptions().addDecryptionKey(secretKeys)); .withOptions(ConsumerOptions.get().addDecryptionKey(secretKeys));
} }
} }

View file

@ -53,7 +53,7 @@ public class VerifyWithMissingPublicKeyCallbackTest {
"is no different than saying you don't care about free speech because you have nothing to say."; "is no different than saying you don't care about free speech because you have nothing to say.";
ByteArrayOutputStream signOut = new ByteArrayOutputStream(); ByteArrayOutputStream signOut = new ByteArrayOutputStream();
EncryptionStream signingStream = PGPainless.encryptAndOrSign().onOutputStream(signOut) EncryptionStream signingStream = PGPainless.encryptAndOrSign().onOutputStream(signOut)
.withOptions(ProducerOptions.sign(new SigningOptions().addInlineSignature( .withOptions(ProducerOptions.sign(SigningOptions.get().addInlineSignature(
SecretKeyRingProtector.unprotectedKeys(), SecretKeyRingProtector.unprotectedKeys(),
signingSecKeys.getPGPSecretKeyRing(), DocumentSignatureType.CANONICAL_TEXT_DOCUMENT signingSecKeys.getPGPSecretKeyRing(), DocumentSignatureType.CANONICAL_TEXT_DOCUMENT
))); )));
@ -62,7 +62,7 @@ public class VerifyWithMissingPublicKeyCallbackTest {
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify() DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(signOut.toByteArray())) .onInputStream(new ByteArrayInputStream(signOut.toByteArray()))
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(unrelatedKeys) .addVerificationCert(unrelatedKeys)
.setMissingCertificateCallback(new OpenPGPKeyMaterialProvider.OpenPGPCertificateProvider() { .setMissingCertificateCallback(new OpenPGPKeyMaterialProvider.OpenPGPCertificateProvider() {
@Override @Override

View file

@ -94,7 +94,7 @@ public class WrongSignerUserIdTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify().onInputStream( DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify().onInputStream(
new ByteArrayInputStream(messageWithWrongUserId.getBytes(StandardCharsets.UTF_8))) new ByteArrayInputStream(messageWithWrongUserId.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys) .addDecryptionKey(secretKeys)
.addVerificationCert(certificate)); .addVerificationCert(certificate));

View file

@ -96,7 +96,7 @@ public class BcHashContextSignerTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(messageIn) .onInputStream(messageIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(certificate) .addVerificationCert(certificate)
.addVerificationOfDetachedSignature(signature)); .addVerificationOfDetachedSignature(signature));

View file

@ -135,7 +135,7 @@ public class EncryptDecryptTest {
.onOutputStream(envelope) .onOutputStream(envelope)
.withOptions(ProducerOptions.signAndEncrypt( .withOptions(ProducerOptions.signAndEncrypt(
EncryptionOptions.encryptCommunications().addRecipient(recipientPub), EncryptionOptions.encryptCommunications().addRecipient(recipientPub),
new SigningOptions().addInlineSignature(keyDecryptor, senderSec, DocumentSignatureType.BINARY_DOCUMENT) SigningOptions.get().addInlineSignature(keyDecryptor, senderSec, DocumentSignatureType.BINARY_DOCUMENT)
)); ));
Streams.pipeAll(new ByteArrayInputStream(secretMessage), encryptor); Streams.pipeAll(new ByteArrayInputStream(secretMessage), encryptor);
@ -156,7 +156,7 @@ public class EncryptDecryptTest {
ByteArrayInputStream envelopeIn = new ByteArrayInputStream(encryptedSecretMessage); ByteArrayInputStream envelopeIn = new ByteArrayInputStream(encryptedSecretMessage);
DecryptionStream decryptor = PGPainless.decryptAndOrVerify() DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(envelopeIn) .onInputStream(envelopeIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(recipientSec, keyDecryptor) .addDecryptionKey(recipientSec, keyDecryptor)
.addVerificationCert(senderPub) .addVerificationCert(senderPub)
); );
@ -184,7 +184,7 @@ public class EncryptDecryptTest {
ByteArrayOutputStream dummyOut = new ByteArrayOutputStream(); ByteArrayOutputStream dummyOut = new ByteArrayOutputStream();
EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(dummyOut) EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(dummyOut)
.withOptions(ProducerOptions.sign( .withOptions(ProducerOptions.sign(
new SigningOptions().addDetachedSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT) SigningOptions.get().addDetachedSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
)); ));
Streams.pipeAll(inputStream, signer); Streams.pipeAll(inputStream, signer);
signer.close(); signer.close();
@ -205,7 +205,7 @@ public class EncryptDecryptTest {
inputStream = new ByteArrayInputStream(testMessage.getBytes()); inputStream = new ByteArrayInputStream(testMessage.getBytes());
DecryptionStream verifier = PGPainless.decryptAndOrVerify() DecryptionStream verifier = PGPainless.decryptAndOrVerify()
.onInputStream(inputStream) .onInputStream(inputStream)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(armorSig.getBytes())) .addVerificationOfDetachedSignatures(new ByteArrayInputStream(armorSig.getBytes()))
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(signingKeys)) .addVerificationCert(KeyRingUtils.publicKeyRingFrom(signingKeys))
); );
@ -237,7 +237,7 @@ public class EncryptDecryptTest {
inputStream = new ByteArrayInputStream(signOut.toByteArray()); inputStream = new ByteArrayInputStream(signOut.toByteArray());
DecryptionStream verifier = PGPainless.decryptAndOrVerify() DecryptionStream verifier = PGPainless.decryptAndOrVerify()
.onInputStream(inputStream) .onInputStream(inputStream)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(signingKeys)) .addVerificationCert(KeyRingUtils.publicKeyRingFrom(signingKeys))
); );
signOut = new ByteArrayOutputStream(); signOut = new ByteArrayOutputStream();

View file

@ -66,7 +66,7 @@ public class EncryptionOptionsTest {
@Test @Test
public void testOverrideEncryptionAlgorithmFailsForNULL() { public void testOverrideEncryptionAlgorithmFailsForNULL() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
assertNull(options.getEncryptionAlgorithmOverride()); assertNull(options.getEncryptionAlgorithmOverride());
assertThrows(IllegalArgumentException.class, () -> options.overrideEncryptionAlgorithm(SymmetricKeyAlgorithm.NULL)); assertThrows(IllegalArgumentException.class, () -> options.overrideEncryptionAlgorithm(SymmetricKeyAlgorithm.NULL));
@ -76,7 +76,7 @@ public class EncryptionOptionsTest {
@Test @Test
public void testOverrideEncryptionOptions() { public void testOverrideEncryptionOptions() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
assertNull(options.getEncryptionAlgorithmOverride()); assertNull(options.getEncryptionAlgorithmOverride());
options.overrideEncryptionAlgorithm(SymmetricKeyAlgorithm.AES_128); options.overrideEncryptionAlgorithm(SymmetricKeyAlgorithm.AES_128);
@ -105,7 +105,7 @@ public class EncryptionOptionsTest {
@Test @Test
public void testAddRecipients_AllKeys() { public void testAddRecipients_AllKeys() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
options.addRecipient(publicKeys, EncryptionOptions.encryptToAllCapableSubkeys()); options.addRecipient(publicKeys, EncryptionOptions.encryptToAllCapableSubkeys());
Set<OpenPGPCertificate.OpenPGPComponentKey> encryptionKeys = options.getEncryptionKeys(); Set<OpenPGPCertificate.OpenPGPComponentKey> encryptionKeys = options.getEncryptionKeys();
@ -117,7 +117,7 @@ public class EncryptionOptionsTest {
@Test @Test
public void testAddEmptyRecipientsFails() { public void testAddEmptyRecipientsFails() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
assertThrows(IllegalArgumentException.class, () -> options.addRecipients(Collections.emptyList())); assertThrows(IllegalArgumentException.class, () -> options.addRecipients(Collections.emptyList()));
assertThrows(IllegalArgumentException.class, () -> options.addRecipients(Collections.emptyList(), assertThrows(IllegalArgumentException.class, () -> options.addRecipients(Collections.emptyList(),
ArrayList::new)); ArrayList::new));
@ -125,14 +125,14 @@ public class EncryptionOptionsTest {
@Test @Test
public void testAddEmptyPassphraseFails() { public void testAddEmptyPassphraseFails() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
assertThrows(IllegalArgumentException.class, () -> assertThrows(IllegalArgumentException.class, () ->
options.addMessagePassphrase(Passphrase.emptyPassphrase())); options.addMessagePassphrase(Passphrase.emptyPassphrase()));
} }
@Test @Test
public void testAddRecipient_KeyWithoutEncryptionKeyFails() { public void testAddRecipient_KeyWithoutEncryptionKeyFails() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
OpenPGPKey secretKeys = PGPainless.buildKeyRing() OpenPGPKey secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) .setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
.addUserId("test@pgpainless.org") .addUserId("test@pgpainless.org")
@ -144,7 +144,7 @@ public class EncryptionOptionsTest {
@Test @Test
public void testEncryptionKeySelectionStrategyEmpty_ThrowsAssertionError() { public void testEncryptionKeySelectionStrategyEmpty_ThrowsAssertionError() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
assertThrows(KeyException.UnacceptableEncryptionKeyException.class, assertThrows(KeyException.UnacceptableEncryptionKeyException.class,
() -> options.addRecipient(publicKeys, new EncryptionOptions.EncryptionKeySelector() { () -> options.addRecipient(publicKeys, new EncryptionOptions.EncryptionKeySelector() {
@ -173,14 +173,14 @@ public class EncryptionOptionsTest {
PGPPublicKeyRingCollection collection = new PGPPublicKeyRingCollection( PGPPublicKeyRingCollection collection = new PGPPublicKeyRingCollection(
Arrays.asList(publicKeys.getPGPPublicKeyRing(), secondKeyRing)); Arrays.asList(publicKeys.getPGPPublicKeyRing(), secondKeyRing));
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
options.addRecipients(collection, EncryptionOptions.encryptToFirstSubkey()); options.addRecipients(collection, EncryptionOptions.encryptToFirstSubkey());
assertEquals(2, options.getEncryptionKeyIdentifiers().size()); assertEquals(2, options.getEncryptionKeyIdentifiers().size());
} }
@Test @Test
public void testAddRecipient_withValidUserId() { public void testAddRecipient_withValidUserId() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
options.addRecipient(publicKeys, "test@pgpainless.org", EncryptionOptions.encryptToFirstSubkey()); options.addRecipient(publicKeys, "test@pgpainless.org", EncryptionOptions.encryptToFirstSubkey());
assertEquals(1, options.getEncryptionMethods().size()); assertEquals(1, options.getEncryptionMethods().size());
@ -188,7 +188,7 @@ public class EncryptionOptionsTest {
@Test @Test
public void testAddRecipient_withInvalidUserId() { public void testAddRecipient_withInvalidUserId() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = EncryptionOptions.get();
assertThrows(KeyException.UnboundUserIdException.class, () -> options.addRecipient(publicKeys, "invalid@user.id")); assertThrows(KeyException.UnboundUserIdException.class, () -> options.addRecipient(publicKeys, "invalid@user.id"));
} }
} }

View file

@ -74,7 +74,7 @@ public class FileInformationTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(cryptIn) .onInputStream(cryptIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKey)); .addDecryptionKey(secretKey));
Streams.pipeAll(decryptionStream, plainOut); Streams.pipeAll(decryptionStream, plainOut);
@ -113,7 +113,7 @@ public class FileInformationTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(cryptIn) .onInputStream(cryptIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKey)); .addDecryptionKey(secretKey));
Streams.pipeAll(decryptionStream, plainOut); Streams.pipeAll(decryptionStream, plainOut);
@ -155,7 +155,7 @@ public class FileInformationTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(cryptIn) .onInputStream(cryptIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKey)); .addDecryptionKey(secretKey));
Streams.pipeAll(decryptionStream, plainOut); Streams.pipeAll(decryptionStream, plainOut);

View file

@ -55,7 +55,7 @@ public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out) EncryptionStream encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
.withOptions( .withOptions(
ProducerOptions.encrypt(new EncryptionOptions() ProducerOptions.encrypt(EncryptionOptions.get()
.addRecipient(publicKeys) // no user-id passed .addRecipient(publicKeys) // no user-id passed
)); ));
@ -67,7 +67,7 @@ public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream();
encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out) encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
.withOptions( .withOptions(
ProducerOptions.encrypt(new EncryptionOptions() ProducerOptions.encrypt(EncryptionOptions.get()
.addRecipient(publicKeys, "Bob Babbage <bob@openpgp.example>") .addRecipient(publicKeys, "Bob Babbage <bob@openpgp.example>")
)); ));
@ -79,7 +79,7 @@ public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream();
encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out) encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
.withOptions( .withOptions(
ProducerOptions.encrypt(new EncryptionOptions() ProducerOptions.encrypt(EncryptionOptions.get()
.addRecipient(publicKeys, "Bobby128 <bobby@aes128.example>") .addRecipient(publicKeys, "Bobby128 <bobby@aes128.example>")
)); ));

View file

@ -69,7 +69,7 @@ public class SigningTest {
EncryptionOptions.encryptDataAtRest() EncryptionOptions.encryptDataAtRest()
.addRecipients(keys) .addRecipients(keys)
.addRecipient(KeyRingUtils.publicKeyRingFrom(cryptieKeys)), .addRecipient(KeyRingUtils.publicKeyRingFrom(cryptieKeys)),
new SigningOptions().addInlineSignature( SigningOptions.get().addInlineSignature(
SecretKeyRingProtector.unlockSingleKeyWith(TestKeys.CRYPTIE_PASSPHRASE, cryptieSigningKey), SecretKeyRingProtector.unlockSingleKeyWith(TestKeys.CRYPTIE_PASSPHRASE, cryptieSigningKey),
cryptieKeys, TestKeys.CRYPTIE_UID, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT) cryptieKeys, TestKeys.CRYPTIE_UID, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)
).setAsciiArmor(true)); ).setAsciiArmor(true));
@ -94,7 +94,7 @@ public class SigningTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(cryptIn) .onInputStream(cryptIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKeys(secretKeys, SecretKeyRingProtector.unprotectedKeys()) .addDecryptionKeys(secretKeys, SecretKeyRingProtector.unprotectedKeys())
.addVerificationCerts(verificationKeys) .addVerificationCerts(verificationKeys)
); );
@ -119,7 +119,7 @@ public class SigningTest {
.getPGPSecretKeyRing(); .getPGPSecretKeyRing();
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("password123")); SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("password123"));
SigningOptions opts = new SigningOptions(); SigningOptions opts = SigningOptions.get();
// "bob" is not a valid user-id // "bob" is not a valid user-id
assertThrows(KeyException.UnboundUserIdException.class, assertThrows(KeyException.UnboundUserIdException.class,
() -> opts.addInlineSignature(protector, secretKeys, "bob", () -> opts.addInlineSignature(protector, secretKeys, "bob",
@ -141,7 +141,7 @@ public class SigningTest {
final PGPSecretKeyRing fSecretKeys = secretKeys; final PGPSecretKeyRing fSecretKeys = secretKeys;
SigningOptions opts = new SigningOptions(); SigningOptions opts = SigningOptions.get();
// "alice" has been revoked // "alice" has been revoked
assertThrows(KeyException.UnboundUserIdException.class, assertThrows(KeyException.UnboundUserIdException.class,
() -> opts.addInlineSignature(protector, fSecretKeys, "alice", () -> opts.addInlineSignature(protector, fSecretKeys, "alice",
@ -154,7 +154,7 @@ public class SigningTest {
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
SigningOptions options = new SigningOptions(); SigningOptions options = SigningOptions.get();
assertNull(options.getHashAlgorithmOverride()); assertNull(options.getHashAlgorithmOverride());
options.overrideHashAlgorithm(HashAlgorithm.SHA224); options.overrideHashAlgorithm(HashAlgorithm.SHA224);
@ -192,7 +192,7 @@ public class SigningTest {
.build() .build()
.getPGPSecretKeyRing(); .getPGPSecretKeyRing();
SigningOptions options = new SigningOptions() SigningOptions options = SigningOptions.get()
.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys, .addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys,
DocumentSignatureType.BINARY_DOCUMENT); DocumentSignatureType.BINARY_DOCUMENT);
String data = "Hello, World!\n"; String data = "Hello, World!\n";
@ -223,7 +223,7 @@ public class SigningTest {
.build() .build()
.getPGPSecretKeyRing(); .getPGPSecretKeyRing();
SigningOptions options = new SigningOptions() SigningOptions options = SigningOptions.get()
.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys, .addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys,
DocumentSignatureType.BINARY_DOCUMENT); DocumentSignatureType.BINARY_DOCUMENT);
String data = "Hello, World!\n"; String data = "Hello, World!\n";
@ -251,7 +251,7 @@ public class SigningTest {
.build() .build()
.getPGPSecretKeyRing(); .getPGPSecretKeyRing();
SigningOptions options = new SigningOptions(); SigningOptions options = SigningOptions.get();
assertThrows(KeyException.UnacceptableSigningKeyException.class, () -> options.addDetachedSignature( assertThrows(KeyException.UnacceptableSigningKeyException.class, () -> options.addDetachedSignature(
SecretKeyRingProtector.unprotectedKeys(), secretKeys, DocumentSignatureType.BINARY_DOCUMENT)); SecretKeyRingProtector.unprotectedKeys(), secretKeys, DocumentSignatureType.BINARY_DOCUMENT));
assertThrows(KeyException.UnacceptableSigningKeyException.class, () -> options.addInlineSignature( assertThrows(KeyException.UnacceptableSigningKeyException.class, () -> options.addInlineSignature(
@ -268,7 +268,7 @@ public class SigningTest {
.build() .build()
.getPGPSecretKeyRing(); .getPGPSecretKeyRing();
SigningOptions options = new SigningOptions(); SigningOptions options = SigningOptions.get();
assertThrows(KeyException.UnboundUserIdException.class, () -> assertThrows(KeyException.UnboundUserIdException.class, () ->
options.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys, "Bob", options.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys, "Bob",
DocumentSignatureType.BINARY_DOCUMENT)); DocumentSignatureType.BINARY_DOCUMENT));

View file

@ -154,7 +154,7 @@ public class Encrypt {
EncryptionOptions.encryptCommunications() EncryptionOptions.encryptCommunications()
.addRecipient(certificateBob) .addRecipient(certificateBob)
.addRecipient(certificateAlice), .addRecipient(certificateAlice),
new SigningOptions() SigningOptions.get()
.addInlineSignature(protectorAlice, keyAlice, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT) .addInlineSignature(protectorAlice, keyAlice, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)
).setAsciiArmor(true) ).setAsciiArmor(true)
); );
@ -167,7 +167,7 @@ public class Encrypt {
// Decrypt and verify signatures // Decrypt and verify signatures
DecryptionStream decryptor = PGPainless.decryptAndOrVerify() DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8))) .onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(keyBob, protectorBob) .addDecryptionKey(keyBob, protectorBob)
.addVerificationCert(certificateAlice) .addVerificationCert(certificateAlice)
); );
@ -209,7 +209,7 @@ public class Encrypt {
// Decrypt // Decrypt
DecryptionStream decryptor = PGPainless.decryptAndOrVerify() DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(asciiCiphertext.getBytes(StandardCharsets.UTF_8))) .onInputStream(new ByteArrayInputStream(asciiCiphertext.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions().addMessagePassphrase(Passphrase.fromPassword("p4ssphr4s3"))); .withOptions(ConsumerOptions.get().addMessagePassphrase(Passphrase.fromPassword("p4ssphr4s3")));
ByteArrayOutputStream plaintext = new ByteArrayOutputStream(); ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
Streams.pipeAll(decryptor, plaintext); Streams.pipeAll(decryptor, plaintext);
@ -273,7 +273,7 @@ public class Encrypt {
// Decrypt and verify signatures // Decrypt and verify signatures
DecryptionStream decryptor = PGPainless.decryptAndOrVerify() DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8))) .onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(keyBob, protectorBob) .addDecryptionKey(keyBob, protectorBob)
.addVerificationCert(certificateAlice) .addVerificationCert(certificateAlice)
); );

View file

@ -106,7 +106,7 @@ public class StupidAlgorithmPreferenceEncryptionTest {
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign() EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
.onOutputStream(out) .onOutputStream(out)
.withOptions(ProducerOptions.encrypt( .withOptions(ProducerOptions.encrypt(
new EncryptionOptions().addRecipient(certificate) EncryptionOptions.get().addRecipient(certificate)
)); ));
encryptionStream.write("Hello".getBytes(StandardCharsets.UTF_8)); encryptionStream.write("Hello".getBytes(StandardCharsets.UTF_8));

View file

@ -144,7 +144,7 @@ public class FixUserIdDoesNotBreakEncryptionCapabilityTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign() EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
.onOutputStream(out) .onOutputStream(out)
.withOptions(ProducerOptions.encrypt(new EncryptionOptions() .withOptions(ProducerOptions.encrypt(EncryptionOptions.get()
.addRecipient(cert))); .addRecipient(cert)));
encryptionStream.write("Hello".getBytes(StandardCharsets.UTF_8)); encryptionStream.write("Hello".getBytes(StandardCharsets.UTF_8));
@ -157,7 +157,7 @@ public class FixUserIdDoesNotBreakEncryptionCapabilityTest {
ByteArrayOutputStream plain = new ByteArrayOutputStream(); ByteArrayOutputStream plain = new ByteArrayOutputStream();
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(edited)); .addDecryptionKey(edited));
Streams.pipeAll(decryptionStream, plain); Streams.pipeAll(decryptionStream, plain);

View file

@ -111,7 +111,7 @@ public class S2KUsageFixTest {
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(keys, protector)); .addDecryptionKey(keys, protector));
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
Streams.pipeAll(decryptionStream, out); Streams.pipeAll(decryptionStream, out);

View file

@ -1384,7 +1384,7 @@ public class CertificateValidatorTest {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(DATA.getBytes(StandardCharsets.UTF_8))) .onInputStream(new ByteArrayInputStream(DATA.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(PGPainless.readKeyRing().publicKeyRing(CERT)) .addVerificationCert(PGPainless.readKeyRing().publicKeyRing(CERT))
.addVerificationOfDetachedSignatures(new ByteArrayInputStream(SIG.getBytes(StandardCharsets.UTF_8)))); .addVerificationOfDetachedSignatures(new ByteArrayInputStream(SIG.getBytes(StandardCharsets.UTF_8))));

View file

@ -144,7 +144,7 @@ public class IgnoreMarkerPacketsTest {
InputStream messageIn = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); InputStream messageIn = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(messageIn) .onInputStream(messageIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addVerificationCert(publicKeys) .addVerificationCert(publicKeys)
.addVerificationOfDetachedSignature(signature) .addVerificationOfDetachedSignature(signature)
); );
@ -193,7 +193,7 @@ public class IgnoreMarkerPacketsTest {
InputStream messageIn = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)); InputStream messageIn = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(messageIn) .onInputStream(messageIn)
.withOptions(new ConsumerOptions() .withOptions(ConsumerOptions.get()
.addDecryptionKey(secretKeys) .addDecryptionKey(secretKeys)
.addVerificationCert(publicKeys) .addVerificationCert(publicKeys)
); );