1 package club.wpia.gigi.crypto.key;
3 import java.security.PublicKey;
4 import java.util.Collections;
5 import java.util.LinkedHashSet;
9 import club.wpia.gigi.GigiApiException;
11 public abstract class KeyCheck {
13 protected static final Set<KeyCheck> checks = new LinkedHashSet<KeyCheck>();
15 public static List<KeyCheck> getChecks() {
16 return Collections.list(Collections.enumeration(checks));
19 public static void register(KeyCheck check) {
23 public abstract void check(PublicKey key) throws GigiApiException;
25 public static void checkKey(PublicKey key) throws GigiApiException {
27 if (checks.isEmpty() || checks.size() < 3) {
28 // Mandatory checks are registered here
29 register(new KeyCheckPublicKeyFormat());
30 register(new KeyCheckSmallFactors());
31 register(new KeyCheckROCA());
35 throw new GigiApiException("Failed key sanity check: No key given!");
38 for (KeyCheck kc : checks) {
45 public boolean equals(Object o) {
54 return getClass().equals(o.getClass());
58 public int hashCode() {
59 return getClass().hashCode();