mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-27 06:42:05 +01:00
Encrypt to all capable subkeys by default
This commit is contained in:
parent
7490eb925f
commit
9a485a3354
2 changed files with 20 additions and 3 deletions
|
@ -24,6 +24,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||||
|
@ -70,7 +72,7 @@ public class EncryptionOptions {
|
||||||
private final Set<SubkeyIdentifier> encryptionKeys = new LinkedHashSet<>();
|
private final Set<SubkeyIdentifier> encryptionKeys = new LinkedHashSet<>();
|
||||||
private final Map<SubkeyIdentifier, KeyRingInfo> keyRingInfo = new HashMap<>();
|
private final Map<SubkeyIdentifier, KeyRingInfo> keyRingInfo = new HashMap<>();
|
||||||
private final Map<SubkeyIdentifier, KeyAccessor> keyViews = new HashMap<>();
|
private final Map<SubkeyIdentifier, KeyAccessor> keyViews = new HashMap<>();
|
||||||
private final EncryptionKeySelector encryptionKeySelector = encryptToFirstSubkey();
|
private final EncryptionKeySelector encryptionKeySelector = encryptToAllCapableSubkeys();
|
||||||
|
|
||||||
private SymmetricKeyAlgorithm encryptionAlgorithmOverride = null;
|
private SymmetricKeyAlgorithm encryptionAlgorithmOverride = null;
|
||||||
|
|
||||||
|
@ -119,6 +121,21 @@ public class EncryptionOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add all key rings in the provided key ring collection as recipients.
|
||||||
|
* Per key ring, the selector is applied to select one or more encryption subkeys.
|
||||||
|
*
|
||||||
|
* @param keys keys
|
||||||
|
* @param selector encryption key selector
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public EncryptionOptions addRecipients(@Nonnull PGPPublicKeyRingCollection keys, @Nonnull EncryptionKeySelector selector) {
|
||||||
|
for (PGPPublicKeyRing key : keys) {
|
||||||
|
addRecipient(key, selector);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a recipient by providing a key and recipient user-id.
|
* Add a recipient by providing a key and recipient user-id.
|
||||||
* The user-id is used to determine the recipients preferences (algorithms etc.).
|
* The user-id is used to determine the recipients preferences (algorithms etc.).
|
||||||
|
|
|
@ -179,14 +179,14 @@ public class EncryptionOptionsTest {
|
||||||
Arrays.asList(publicKeys, secondKeyRing));
|
Arrays.asList(publicKeys, secondKeyRing));
|
||||||
|
|
||||||
EncryptionOptions options = new EncryptionOptions();
|
EncryptionOptions options = new EncryptionOptions();
|
||||||
options.addRecipients(collection);
|
options.addRecipients(collection, EncryptionOptions.encryptToFirstSubkey());
|
||||||
assertEquals(2, options.getEncryptionKeyIdentifiers().size());
|
assertEquals(2, options.getEncryptionKeyIdentifiers().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddRecipient_withValidUserId() {
|
public void testAddRecipient_withValidUserId() {
|
||||||
EncryptionOptions options = new EncryptionOptions();
|
EncryptionOptions options = new EncryptionOptions();
|
||||||
options.addRecipient(publicKeys, "test@pgpainless.org");
|
options.addRecipient(publicKeys, "test@pgpainless.org", EncryptionOptions.encryptToFirstSubkey());
|
||||||
|
|
||||||
assertEquals(1, options.getEncryptionMethods().size());
|
assertEquals(1, options.getEncryptionMethods().size());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue