use of de.carne.jfx.util.DefaultSet in project certmgr by hdecarne.
the class SignatureAlgorithm method getDefaultSet.
/**
* Get the available signature algorithms.
*
* @param keyPairAlgorithm The key pair algorithm to get the signature algorithms for.
* @param defaultHint The default to return (may be {@code null}). If this algorithm is contained in the default
* set, it is also set as the default.
* @param expertMode Whether only standard algorithms are considered ({@code false}) or all algorithms available on
* the current platform ({@code true}).
* @return The available signature algorithms
*/
public static DefaultSet<SignatureAlgorithm> getDefaultSet(String keyPairAlgorithm, @Nullable String defaultHint, boolean expertMode) {
DefaultSet<SignatureAlgorithm> signatureAlgorithms = new DefaultSet<>();
DefaultSet<String> defaultNames = SecurityDefaults.getSignatureAlgorithmNames(keyPairAlgorithm);
@Nullable String defaultName = (defaultHint != null && defaultNames.contains(defaultHint) ? defaultHint : defaultNames.getDefault());
if (defaultName != null) {
defaultName = defaultName.toUpperCase();
}
for (Provider provider : SecurityDefaults.getProviders(expertMode)) {
for (Provider.Service service : provider.getServices()) {
if (!SERVICE_TYPE_SIGNATURE.equals(service.getType())) {
continue;
}
String upperCaseAlgorithm = service.getAlgorithm().toUpperCase();
if (!expertMode && !defaultNames.contains(upperCaseAlgorithm)) {
continue;
}
SignatureAlgorithm signatureAlgorithm = (expertMode ? new ExpertKeyPairAlgorithm(service) : new StandardKeyPairAlgorithm(service));
if (upperCaseAlgorithm.equals(defaultName)) {
signatureAlgorithms.addDefault(signatureAlgorithm);
} else {
signatureAlgorithms.add(signatureAlgorithm);
}
}
}
return signatureAlgorithms;
}
Aggregations