mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-14 20:59:39 +02:00
In PasswordBasedSecretKeyRingProtector.forKey(ring, passphrase): Return passphrase also for subkeys
Fixes #97, thanks @DenBond7
This commit is contained in:
parent
7bd12fe5d4
commit
8c97b6ead1
2 changed files with 24 additions and 2 deletions
|
@ -18,10 +18,16 @@ package org.pgpainless.key.protection;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
@ -56,4 +62,15 @@ public class PassphraseProtectedKeyTest {
|
|||
assertNull(protector.getEncryptor(TestKeys.JULIET_KEY_ID));
|
||||
assertNull(protector.getDecryptor(TestKeys.JULIET_KEY_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnsNonNullDecryptorForSubkeys() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().modernKeyRing("alice", "passphrase");
|
||||
SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("passphrase"));
|
||||
for (Iterator<PGPPublicKey> it = secretKeys.getPublicKeys(); it.hasNext(); ) {
|
||||
PGPPublicKey subkey = it.next();
|
||||
assertNotNull(protector.getEncryptor(subkey.getKeyID()));
|
||||
assertNotNull(protector.getDecryptor(subkey.getKeyID()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue