mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-26 14:22:05 +01:00
EncryptionOptions.addRecipients(collection): Disallow empty collections
Fixes #281
This commit is contained in:
parent
51cd75533b
commit
b980fcd7b1
2 changed files with 14 additions and 0 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue