mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 04:42:06 +01:00
Add toRecipients method and better check for zero keys
This commit is contained in:
parent
9868390c66
commit
d5f034bab1
2 changed files with 36 additions and 6 deletions
|
@ -64,9 +64,6 @@ public class EncryptionBuilder implements EncryptionBuilderInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WithAlgorithms toRecipients(PGPPublicKey... keys) {
|
public WithAlgorithms toRecipients(PGPPublicKey... keys) {
|
||||||
if (keys.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Recipient list MUST NOT be empty.");
|
|
||||||
}
|
|
||||||
for (PGPPublicKey k : keys) {
|
for (PGPPublicKey k : keys) {
|
||||||
if (encryptionKeySelector().accept(null, k)) {
|
if (encryptionKeySelector().accept(null, k)) {
|
||||||
EncryptionBuilder.this.encryptionKeys.add(k);
|
EncryptionBuilder.this.encryptionKeys.add(k);
|
||||||
|
@ -74,14 +71,16 @@ public class EncryptionBuilder implements EncryptionBuilderInterface {
|
||||||
throw new IllegalArgumentException("Key " + k.getKeyID() + " is not a valid encryption key.");
|
throw new IllegalArgumentException("Key " + k.getKeyID() + " is not a valid encryption key.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (EncryptionBuilder.this.encryptionKeys.isEmpty()) {
|
||||||
|
throw new IllegalStateException("No valid encryption keys found!");
|
||||||
|
}
|
||||||
|
|
||||||
return new WithAlgorithmsImpl();
|
return new WithAlgorithmsImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WithAlgorithms toRecipients(PGPPublicKeyRing... keys) {
|
public WithAlgorithms toRecipients(PGPPublicKeyRing... keys) {
|
||||||
if (keys.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Recipient list MUST NOT be empty.");
|
|
||||||
}
|
|
||||||
for (PGPPublicKeyRing ring : keys) {
|
for (PGPPublicKeyRing ring : keys) {
|
||||||
for (PGPPublicKey k : ring) {
|
for (PGPPublicKey k : ring) {
|
||||||
if (encryptionKeySelector().accept(null, k)) {
|
if (encryptionKeySelector().accept(null, k)) {
|
||||||
|
@ -89,6 +88,30 @@ public class EncryptionBuilder implements EncryptionBuilderInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (EncryptionBuilder.this.encryptionKeys.isEmpty()) {
|
||||||
|
throw new IllegalStateException("No valid encryption keys found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WithAlgorithmsImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WithAlgorithms toRecipients(PGPPublicKeyRingCollection... keys) {
|
||||||
|
for (PGPPublicKeyRingCollection collection : keys) {
|
||||||
|
for (PGPPublicKeyRing ring : collection) {
|
||||||
|
for (PGPPublicKey k : ring) {
|
||||||
|
if (encryptionKeySelector().accept(null, k)) {
|
||||||
|
EncryptionBuilder.this.encryptionKeys.add(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EncryptionBuilder.this.encryptionKeys.isEmpty()) {
|
||||||
|
throw new IllegalStateException("No valid encryption keys found!");
|
||||||
|
}
|
||||||
|
|
||||||
return new WithAlgorithmsImpl();
|
return new WithAlgorithmsImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +132,11 @@ public class EncryptionBuilder implements EncryptionBuilderInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (EncryptionBuilder.this.encryptionKeys.isEmpty()) {
|
||||||
|
throw new IllegalStateException("No valid encryption keys found!");
|
||||||
|
}
|
||||||
|
|
||||||
return new WithAlgorithmsImpl();
|
return new WithAlgorithmsImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,8 @@ public interface EncryptionBuilderInterface {
|
||||||
|
|
||||||
WithAlgorithms toRecipients(PGPPublicKeyRing... keys);
|
WithAlgorithms toRecipients(PGPPublicKeyRing... keys);
|
||||||
|
|
||||||
|
WithAlgorithms toRecipients(PGPPublicKeyRingCollection... keys);
|
||||||
|
|
||||||
<O> WithAlgorithms toRecipients(PublicKeyRingSelectionStrategy<O> selectionStrategy,
|
<O> WithAlgorithms toRecipients(PublicKeyRingSelectionStrategy<O> selectionStrategy,
|
||||||
MultiMap<O, PGPPublicKeyRingCollection> keys);
|
MultiMap<O, PGPPublicKeyRingCollection> keys);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue