1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-27 13:28:00 +01:00

Tests: Make use of KeyRingInfo to determine encryption subkeys

This commit is contained in:
Paul Schaub 2021-06-23 19:20:47 +02:00
parent df22c2a102
commit e7f685e63b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -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<PGPPublicKey> encryptionKeys = new EncryptionKeySelectionStrategy(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS)
.selectKeysFromKeyRing(KeyRingUtils.publicKeyRingFrom(secretKeys));
KeyRingInfo info = new KeyRingInfo(secretKeys);
List<PGPPublicKey> encryptionKeys = info.getEncryptionSubkeys(EncryptionPurpose.STORAGE_AND_COMMUNICATIONS);
assertEquals(1, encryptionKeys.size());
assertEquals(new OpenPgpV4Fingerprint(encryptionKeys.iterator().next()), metadata.getDecryptionFingerprint());