1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-22 20:32:05 +01:00

EncryptionOptions.addRecipients(collection): Disallow empty collections

Fixes #281
This commit is contained in:
Paul Schaub 2022-04-29 22:49:45 +02:00
parent 51cd75533b
commit b980fcd7b1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 14 additions and 0 deletions

View file

@ -107,6 +107,9 @@ public class EncryptionOptions {
* @return this * @return this
*/ */
public EncryptionOptions addRecipients(Iterable<PGPPublicKeyRing> keys) { public EncryptionOptions addRecipients(Iterable<PGPPublicKeyRing> keys) {
if (!keys.iterator().hasNext()) {
throw new IllegalArgumentException("Set of recipient keys cannot be empty.");
}
for (PGPPublicKeyRing key : keys) { for (PGPPublicKeyRing key : keys) {
addRecipient(key); addRecipient(key);
} }
@ -122,6 +125,9 @@ public class EncryptionOptions {
* @return this * @return this
*/ */
public EncryptionOptions addRecipients(@Nonnull Iterable<PGPPublicKeyRing> keys, @Nonnull EncryptionKeySelector selector) { public EncryptionOptions addRecipients(@Nonnull Iterable<PGPPublicKeyRing> keys, @Nonnull EncryptionKeySelector selector) {
if (!keys.iterator().hasNext()) {
throw new IllegalArgumentException("Set of recipient keys cannot be empty.");
}
for (PGPPublicKeyRing key : keys) { for (PGPPublicKeyRing key : keys) {
addRecipient(key, selector); addRecipient(key, selector);
} }

View file

@ -116,6 +116,14 @@ public class EncryptionOptionsTest {
assertTrue(encryptionKeys.contains(encryptStorage)); assertTrue(encryptionKeys.contains(encryptStorage));
} }
@Test
public void testAddEmptyRecipientsFails() {
EncryptionOptions options = new EncryptionOptions();
assertThrows(IllegalArgumentException.class, () -> options.addRecipients(Collections.emptyList()));
assertThrows(IllegalArgumentException.class, () -> options.addRecipients(Collections.emptyList(),
encryptionCapableKeys -> encryptionCapableKeys));
}
@Test @Test
public void testAddEmptyPassphraseFails() { public void testAddEmptyPassphraseFails() {
EncryptionOptions options = new EncryptionOptions(); EncryptionOptions options = new EncryptionOptions();