Search in sources :

Example 6 with DefaultSet

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;
}
Also used : DefaultSet(de.carne.jfx.util.DefaultSet) Service(java.security.Provider.Service) Nullable(de.carne.check.Nullable) Provider(java.security.Provider)

Aggregations

DefaultSet (de.carne.jfx.util.DefaultSet)6 Provider (java.security.Provider)3 Service (java.security.Provider.Service)3 Days (de.carne.certmgr.util.Days)2 Nullable (de.carne.check.Nullable)2 UserCertStoreEntry (de.carne.certmgr.certs.UserCertStoreEntry)1