mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 02:09:38 +02:00
Port TryDecryptWithUnavailableGnuDummyKeyTest
This commit is contained in:
parent
9f35be1b0e
commit
bd24db9cc6
1 changed files with 12 additions and 11 deletions
|
@ -5,8 +5,8 @@
|
|||
package org.pgpainless.decryption_verification;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPCertificate;
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
|
@ -27,26 +27,27 @@ public class TryDecryptWithUnavailableGnuDummyKeyTest {
|
|||
@Test
|
||||
public void testAttemptToDecryptWithRemovedPrivateKeysThrows()
|
||||
throws PGPException, IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Hardy Hardware <hardy@hard.ware>")
|
||||
.getPGPSecretKeyRing();
|
||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
||||
PGPainless api = PGPainless.getInstance();
|
||||
OpenPGPKey secretKeys = api.generateKey()
|
||||
.modernKeyRing("Hardy Hardware <hardy@hard.ware>");
|
||||
OpenPGPCertificate certificate = secretKeys.toCertificate();
|
||||
|
||||
ByteArrayOutputStream ciphertextOut = new ByteArrayOutputStream();
|
||||
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign()
|
||||
EncryptionStream encryptionStream = api.generateMessage()
|
||||
.onOutputStream(ciphertextOut)
|
||||
.withOptions(
|
||||
ProducerOptions.encrypt(EncryptionOptions.get().addRecipient(certificate)));
|
||||
ProducerOptions.encrypt(EncryptionOptions.get(api).addRecipient(certificate)));
|
||||
ByteArrayInputStream plaintextIn = new ByteArrayInputStream("Hello, World!\n".getBytes());
|
||||
Streams.pipeAll(plaintextIn, encryptionStream);
|
||||
encryptionStream.close();
|
||||
|
||||
PGPSecretKeyRing removedKeys = GnuPGDummyKeyUtil.modify(secretKeys)
|
||||
.removePrivateKeys(GnuPGDummyKeyUtil.KeyFilter.any());
|
||||
OpenPGPKey removedKeys = api.toKey(
|
||||
GnuPGDummyKeyUtil.modify(secretKeys)
|
||||
.removePrivateKeys(GnuPGDummyKeyUtil.KeyFilter.any()));
|
||||
|
||||
ByteArrayInputStream ciphertextIn = new ByteArrayInputStream(ciphertextOut.toByteArray());
|
||||
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(ciphertextIn)
|
||||
.withOptions(ConsumerOptions.get().addDecryptionKey(removedKeys)));
|
||||
.withOptions(ConsumerOptions.get(api).addDecryptionKey(removedKeys)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue