All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.nagyesta.lowkeyvault.service.certificate.impl.CertificateAlgorithm Maven / Gradle / Ivy

There is a newer version: 2.5.81
Show newest version
package com.github.nagyesta.lowkeyvault.service.certificate.impl;

import com.github.nagyesta.lowkeyvault.model.v7_2.key.constants.KeyType;
import lombok.Getter;
import lombok.NonNull;

import java.util.Arrays;
import java.util.Optional;
import java.util.Set;

@SuppressWarnings("LombokGetterMayBeUsed")
public enum CertificateAlgorithm {

    /**
     * Certificate signed using RSA algorithm.
     */
    RSA("SHA256withRSA", Set.of(KeyType.RSA, KeyType.RSA_HSM)),
    /**
     * Certificate signed using EC algorithm.
     */
    EC("SHA256withECDSA", Set.of(KeyType.EC, KeyType.EC_HSM));

    @Getter
    private final String algorithm;
    private final Set keyTypes;

    CertificateAlgorithm(final String algorithm, final Set keyTypes) {
        this.algorithm = algorithm;
        this.keyTypes = keyTypes;
    }

    public static CertificateAlgorithm forKeyType(@NonNull final KeyType keyType) {
        final Optional value = Arrays.stream(CertificateAlgorithm.values())
                .filter(v -> v.keyTypes.contains(keyType))
                .findFirst();
        return value.orElseThrow(() -> new IllegalArgumentException("Unable to find certificate algorithm for key type: " + keyType));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy