package com.sunyard.chsm.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

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

/**
 * 数据的填充模式
 *
 * @author Cheney
 */
@Getter
@AllArgsConstructor
public enum Padding {
    NOPadding("NoPadding", "NoPadding"),
    PCKS5Padding("PKCS5Padding", "PKCS5Padding"),
    PCKS7Padding("PKCS7Padding", "PKCS7Padding"),
    ;

    private final String code;
    private final String desc;


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

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