diff options
| author | J08nY | 2017-11-28 16:29:39 +0100 |
|---|---|---|
| committer | J08nY | 2017-11-28 16:29:39 +0100 |
| commit | 5913cd5cb0940623d3bb2ee0861a1fdcfe08f08b (patch) | |
| tree | 1c7e840cb94469d7575249292d926faa9488347d /src/cz/crcs/ectester/standalone/consts/Ident.java | |
| parent | e22139e18d28906f9533a1dc31e0622080b5f35c (diff) | |
| download | ECTester-5913cd5cb0940623d3bb2ee0861a1fdcfe08f08b.tar.gz ECTester-5913cd5cb0940623d3bb2ee0861a1fdcfe08f08b.tar.zst ECTester-5913cd5cb0940623d3bb2ee0861a1fdcfe08f08b.zip | |
Implement ECDSA for standalone libs.
Diffstat (limited to 'src/cz/crcs/ectester/standalone/consts/Ident.java')
| -rw-r--r-- | src/cz/crcs/ectester/standalone/consts/Ident.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/standalone/consts/Ident.java b/src/cz/crcs/ectester/standalone/consts/Ident.java index 84cce2d..e2556c5 100644 --- a/src/cz/crcs/ectester/standalone/consts/Ident.java +++ b/src/cz/crcs/ectester/standalone/consts/Ident.java @@ -1,9 +1,12 @@ package cz.crcs.ectester.standalone.consts; +import java.security.NoSuchAlgorithmException; +import java.security.Provider; import java.util.Arrays; import java.util.Collections; import java.util.Set; import java.util.TreeSet; +import java.util.function.BiFunction; public abstract class Ident { Set<String> idents; @@ -28,6 +31,28 @@ public abstract class Ident { return name.equals(other) || idents.contains(other); } + <T> T getInstance(BiFunction<String, Provider, T> getter, Provider provider) throws NoSuchAlgorithmException { + T instance = null; + try { + instance = getter.apply(name, provider); + } catch (Exception ignored) { + } + + if (instance == null) { + for (String alias : idents) { + try { + instance = getter.apply(alias, provider); + } catch (Exception ignored) { + } + } + } + + if (instance == null) { + throw new NoSuchAlgorithmException(name); + } + return instance; + } + @Override public boolean equals(Object obj) { if (this == obj) { |
