diff options
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) { |
