mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-18 02:12:06 +01:00
Ensure that KeySpecBuilder gets at least one key flag
This commit is contained in:
parent
cff69006f7
commit
387b2b4b43
3 changed files with 18 additions and 5 deletions
|
@ -55,7 +55,7 @@ public class KeySpec {
|
|||
return inheritedSubPackets;
|
||||
}
|
||||
|
||||
public static KeySpecBuilder getBuilder(KeyType type, KeyFlag... flags) {
|
||||
return new KeySpecBuilder(type, flags);
|
||||
public static KeySpecBuilder getBuilder(KeyType type, KeyFlag flag, KeyFlag... flags) {
|
||||
return new KeySpecBuilder(type, flag, flags);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
|
|||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.key.generation.type.KeyType;
|
||||
import org.pgpainless.util.CollectionUtils;
|
||||
|
||||
public class KeySpecBuilder implements KeySpecBuilderInterface {
|
||||
|
||||
|
@ -41,10 +42,14 @@ public class KeySpecBuilder implements KeySpecBuilderInterface {
|
|||
private Set<HashAlgorithm> preferredHashAlgorithms = algorithmSuite.getHashAlgorithms();
|
||||
private Set<SymmetricKeyAlgorithm> preferredSymmetricAlgorithms = algorithmSuite.getSymmetricKeyAlgorithms();
|
||||
|
||||
KeySpecBuilder(@Nonnull KeyType type, KeyFlag... flags) {
|
||||
if (flags == null || flags.length == 0) {
|
||||
throw new IllegalArgumentException("KeyFlags cannot be empty.");
|
||||
KeySpecBuilder(@Nonnull KeyType type, KeyFlag flag, KeyFlag... flags) {
|
||||
if (flag == null) {
|
||||
throw new IllegalArgumentException("Key MUST carry at least one key flag");
|
||||
}
|
||||
if (flags == null) {
|
||||
throw new IllegalArgumentException("List of additional flags MUST NOT be null.");
|
||||
}
|
||||
flags = CollectionUtils.concat(flag, flags);
|
||||
assureKeyCanCarryFlags(type, flags);
|
||||
this.type = type;
|
||||
this.keyFlags = flags;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.pgpainless.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -33,4 +34,11 @@ public final class CollectionUtils {
|
|||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public static <T> T[] concat(T t, T[] ts) {
|
||||
T[] concat = (T[]) Array.newInstance(t.getClass(), ts.length + 1);
|
||||
concat[0] = t;
|
||||
System.arraycopy(ts, 0, concat, 1, ts.length);
|
||||
return concat;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue