package com.sunyard.chsm.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author liulu
 * @since 2024/10/22
 */
@Getter
@AllArgsConstructor
public enum KeyAlg {

    SM1(KeyCategory.SYM_KEY, "SM1", "SM1"),
    SM4(KeyCategory.SYM_KEY, "SM4", "SM4"),
    SM2(KeyCategory.ASYM_KEY, "SM2", "SM2"),
    RSA(KeyCategory.ASYM_KEY, "RSA", "RSA"),
    ;
    private final KeyCategory category;
    private final String code;
    private final String desc;


    public static KeyAlg of(String code) {
        if (code == null || code.trim().isEmpty()) {
            return null;
        }

        return Arrays.stream(KeyAlg.values())
                .filter(it -> Objects.equals(it.code, code))
                .findFirst()
                .orElse(null);
    }
}
