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

Remove deprecated encryption API

This commit is contained in:
Paul Schaub 2021-06-29 16:43:37 +02:00
parent ab347dab43
commit b6eed91f47
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
7 changed files with 39 additions and 456 deletions

View file

@ -153,10 +153,10 @@ public class EncryptDecryptTest {
EncryptionStream encryptor = PGPainless.encryptAndOrSign()
.onOutputStream(envelope)
.toRecipient(recipientPub)
.and()
.signInlineWith(keyDecryptor, senderSec, null, DocumentSignatureType.BINARY_DOCUMENT)
.noArmor();
.withOptions(ProducerOptions.signAndEncrypt(
EncryptionOptions.encryptCommunications().addRecipient(recipientPub),
new SigningOptions().addInlineSignature(keyDecryptor, senderSec, DocumentSignatureType.BINARY_DOCUMENT)
));
Streams.pipeAll(new ByteArrayInputStream(secretMessage), encryptor);
encryptor.close();
@ -205,9 +205,9 @@ public class EncryptDecryptTest {
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
ByteArrayOutputStream dummyOut = new ByteArrayOutputStream();
EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(dummyOut)
.doNotEncrypt()
.signDetachedWith(keyRingProtector, signingKeys)
.noArmor();
.withOptions(ProducerOptions.sign(
new SigningOptions().addDetachedSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
));
Streams.pipeAll(inputStream, signer);
signer.close();
@ -250,9 +250,10 @@ public class EncryptDecryptTest {
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
ByteArrayOutputStream signOut = new ByteArrayOutputStream();
EncryptionStream signer = PGPainless.encryptAndOrSign().onOutputStream(signOut)
.doNotEncrypt()
.signInlineWith(keyRingProtector, signingKeys)
.asciiArmor();
.withOptions(ProducerOptions.sign(
SigningOptions.get()
.addInlineSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
).setAsciiArmor(true));
Streams.pipeAll(inputStream, signer);
signer.close();
@ -328,9 +329,9 @@ public class EncryptDecryptTest {
"-----END PGP PUBLIC KEY BLOCK-----\n";
PGPPublicKeyRing publicKeys = PGPainless.readKeyRing().publicKeyRing(key);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
assertThrows(IllegalArgumentException.class, () ->
PGPainless.encryptAndOrSign().onOutputStream(outputStream)
.toRecipient(publicKeys));
EncryptionOptions.encryptCommunications()
.addRecipient(publicKeys));
}
}

View file

@ -37,10 +37,8 @@ public class EncryptionStreamClosedTest {
OutputStream out = new ByteArrayOutputStream();
EncryptionStream stream = PGPainless.encryptAndOrSign()
.onOutputStream(out)
.forPassphrase(Passphrase.fromPassword("dummy"))
.and()
.doNotSign()
.asciiArmor();
.withOptions(ProducerOptions.encrypt(EncryptionOptions.encryptCommunications()
.addPassphrase(Passphrase.fromPassword("dummy"))));
// No close() called => getResult throws
assertThrows(IllegalStateException.class, stream::getResult);

View file

@ -67,10 +67,11 @@ public class FileInfoTest {
ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
.onOutputStream(dataOut, fileInfo)
.toRecipient(publicKeys)
.and()
.doNotSign()
.noArmor();
.withOptions(ProducerOptions.encrypt(
EncryptionOptions
.encryptCommunications()
.addRecipient(publicKeys))
);
Streams.pipeAll(dataIn, encryptionStream);
encryptionStream.close();

View file

@ -37,8 +37,11 @@ import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.encryption_signing.ProducerOptions;
import org.pgpainless.encryption_signing.SigningOptions;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.KeyRingProtectionSettings;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
@ -192,9 +195,9 @@ public class ChangeSecretKeyRingPassphraseTest {
String dummyMessage = "dummy";
ByteArrayOutputStream dummy = new ByteArrayOutputStream();
EncryptionStream stream = PGPainless.encryptAndOrSign().onOutputStream(dummy)
.doNotEncrypt()
.signInlineWith(PasswordBasedSecretKeyRingProtector.forKey(keyRing, passphrase), keyRing)
.noArmor();
.withOptions(ProducerOptions.sign(SigningOptions.get()
.addInlineSignature(PasswordBasedSecretKeyRingProtector.forKey(keyRing, passphrase),
keyRing, DocumentSignatureType.BINARY_DOCUMENT)));
Streams.pipeAll(new ByteArrayInputStream(dummyMessage.getBytes()), stream);
stream.close();