From e7f685e63b566988f0ca309c4d40bea96108014a Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 23 Jun 2021 19:20:47 +0200 Subject: [PATCH] Tests: Make use of KeyRingInfo to determine encryption subkeys --- .../DecryptHiddenRecipientMessage.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java index 7cc76f33..e86659c7 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java @@ -21,7 +21,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Set; +import java.util.List; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKey; @@ -30,11 +30,10 @@ 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.KeyFlag; +import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; -import org.pgpainless.key.util.KeyRingUtils; -import org.pgpainless.util.selection.key.impl.EncryptionKeySelectionStrategy; +import org.pgpainless.key.info.KeyRingInfo; public class DecryptHiddenRecipientMessage { @@ -155,10 +154,8 @@ public class DecryptHiddenRecipientMessage { OpenPgpMetadata metadata = decryptionStream.getResult(); assertEquals(0, metadata.getRecipientKeyIds().size()); - // Hacky way of getting the encryption subkey of the key ring - // TODO: Create convenient method for this - Set encryptionKeys = new EncryptionKeySelectionStrategy(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS) - .selectKeysFromKeyRing(KeyRingUtils.publicKeyRingFrom(secretKeys)); + KeyRingInfo info = new KeyRingInfo(secretKeys); + List encryptionKeys = info.getEncryptionSubkeys(EncryptionPurpose.STORAGE_AND_COMMUNICATIONS); assertEquals(1, encryptionKeys.size()); assertEquals(new OpenPgpV4Fingerprint(encryptionKeys.iterator().next()), metadata.getDecryptionFingerprint());