X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fclub%2Fwpia%2Fgigi%2Fcrypto%2Fkey%2FKeyCheck.java;fp=src%2Fclub%2Fwpia%2Fgigi%2Fcrypto%2Fkey%2FKeyCheck.java;h=7c1ed82bf026a87160f5f8bf72e30cb06b5b7ff3;hb=376ad64d4bafc4b2db6990604758addf8fabbd3c;hp=0000000000000000000000000000000000000000;hpb=ca40eec05f7b3e6bd02014c30448af786aace969;p=gigi.git diff --git a/src/club/wpia/gigi/crypto/key/KeyCheck.java b/src/club/wpia/gigi/crypto/key/KeyCheck.java new file mode 100644 index 00000000..7c1ed82b --- /dev/null +++ b/src/club/wpia/gigi/crypto/key/KeyCheck.java @@ -0,0 +1,59 @@ +package club.wpia.gigi.crypto.key; + +import java.security.PublicKey; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import club.wpia.gigi.GigiApiException; + +public abstract class KeyCheck { + + protected static final Set checks = new LinkedHashSet(); + + public static List getChecks() { + return Collections.list(Collections.enumeration(checks)); + } + + public static void register(KeyCheck check) { + checks.add(check); + } + + public abstract void check(PublicKey key) throws GigiApiException; + + public static void checkKey(PublicKey key) throws GigiApiException { + + if (checks.isEmpty()) { + // Mandatory checks are registered here + } + + if (key == null) { + throw new GigiApiException("Failed key sanity check: No key given!"); + } + + for (KeyCheck kc : checks) { + kc.check(key); + } + + } + + @Override + public boolean equals(Object o) { + if (o == null) { + return false; + } + + if (o == this) { + return true; + } + + return getClass().equals(o.getClass()); + } + + @Override + public int hashCode() { + return getClass().hashCode(); + } + +}