1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +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.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Set; import java.util.List;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey; 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.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.EncryptionPurpose;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.util.selection.key.impl.EncryptionKeySelectionStrategy;
public class DecryptHiddenRecipientMessage { public class DecryptHiddenRecipientMessage {
@ -155,10 +154,8 @@ public class DecryptHiddenRecipientMessage {
OpenPgpMetadata metadata = decryptionStream.getResult(); OpenPgpMetadata metadata = decryptionStream.getResult();
assertEquals(0, metadata.getRecipientKeyIds().size()); assertEquals(0, metadata.getRecipientKeyIds().size());
// Hacky way of getting the encryption subkey of the key ring KeyRingInfo info = new KeyRingInfo(secretKeys);
// TODO: Create convenient method for this List<PGPPublicKey> encryptionKeys = info.getEncryptionSubkeys(EncryptionPurpose.STORAGE_AND_COMMUNICATIONS);
Set<PGPPublicKey> encryptionKeys = new EncryptionKeySelectionStrategy(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS)
.selectKeysFromKeyRing(KeyRingUtils.publicKeyRingFrom(secretKeys));
assertEquals(1, encryptionKeys.size()); assertEquals(1, encryptionKeys.size());
assertEquals(new OpenPgpV4Fingerprint(encryptionKeys.iterator().next()), metadata.getDecryptionFingerprint()); assertEquals(new OpenPgpV4Fingerprint(encryptionKeys.iterator().next()), metadata.getDecryptionFingerprint());