1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-22 20:32:05 +01:00

Fix test and use new decryption API

This commit is contained in:
Paul Schaub 2021-06-26 18:41:02 +02:00
parent 715ae707ed
commit 60cbcac58b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 10 additions and 9 deletions

View file

@ -32,6 +32,7 @@ import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.encryption_signing.EncryptionOptions;
@ -88,10 +89,10 @@ public class Encrypt {
// Decrypt and verify signatures
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(encryptedMessage.getBytes(StandardCharsets.UTF_8)))
.decryptWith(protectorBob, keyBob)
.verifyWith(certificateAlice)
.ignoreMissingPublicKeys()
.build();
.withOptions(new ConsumerOptions()
.addDecryptionKey(keyBob, protectorBob)
.addVerificationCert(certificateAlice)
);
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
@ -133,9 +134,7 @@ public class Encrypt {
// Decrypt
DecryptionStream decryptor = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(asciiCiphertext.getBytes(StandardCharsets.UTF_8)))
.decryptWith(Passphrase.fromPassword("p4ssphr4s3"))
.doNotVerify()
.build();
.withOptions(new ConsumerOptions().addDecryptionPassphrase(Passphrase.fromPassword("p4ssphr4s3")));
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
Streams.pipeAll(decryptor, plaintext);

View file

@ -228,15 +228,17 @@ public class ModifyKeys {
*/
@Test
public void revokeUserId() throws PGPException {
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAllKeysWith(
Passphrase.fromPassword(originalPassphrase), secretKey);
secretKey = PGPainless.modifyKeyRing(secretKey)
.addUserId("alcie@pgpainless.org", SecretKeyRingProtector.unprotectedKeys())
.addUserId("alcie@pgpainless.org", protector)
.done();
// Initially the user-id is valid
assertTrue(PGPainless.inspectKeyRing(secretKey).isUserIdValid("alcie@pgpainless.org"));
// Revoke the second user-id
secretKey = PGPainless.modifyKeyRing(secretKey)
.revokeUserId("alcie@pgpainless.org", SecretKeyRingProtector.unprotectedKeys())
.revokeUserId("alcie@pgpainless.org", protector)
.done();
// Now the user-id is no longer valid
assertFalse(PGPainless.inspectKeyRing(secretKey).isUserIdValid("alcie@pgpainless.org"));