// 
// Decompiled by Procyon v0.6.0
// 

package com.nimbusds.jose.jwk;

import com.nimbusds.jose.JWEAlgorithm;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.Algorithm;
import com.nimbusds.jose.util.JSONStringUtils;
import com.nimbusds.jose.Requirement;
import com.nimbusds.jose.shaded.jcip.Immutable;
import java.io.Serializable;

@Immutable
public final class KeyType implements Serializable
{
    private static final long serialVersionUID = 1L;
    private final String value;
    private final Requirement requirement;
    public static final KeyType EC;
    public static final KeyType RSA;
    public static final KeyType OCT;
    public static final KeyType OKP;
    
    public KeyType(final String value, final Requirement req) {
        if (value == null) {
            throw new IllegalArgumentException("The key type value must not be null");
        }
        this.value = value;
        this.requirement = req;
    }
    
    public String getValue() {
        return this.value;
    }
    
    public Requirement getRequirement() {
        return this.requirement;
    }
    
    @Override
    public int hashCode() {
        return this.value.hashCode();
    }
    
    @Override
    public boolean equals(final Object object) {
        return object instanceof KeyType && this.toString().equals(object.toString());
    }
    
    @Override
    public String toString() {
        return this.value;
    }
    
    public String toJSONString() {
        return JSONStringUtils.toJSONString(this.value);
    }
    
    public static KeyType parse(final String s) {
        if (s == null) {
            throw new IllegalArgumentException("The key type to parse must not be null");
        }
        if (s.equals(KeyType.EC.getValue())) {
            return KeyType.EC;
        }
        if (s.equals(KeyType.RSA.getValue())) {
            return KeyType.RSA;
        }
        if (s.equals(KeyType.OCT.getValue())) {
            return KeyType.OCT;
        }
        if (s.equals(KeyType.OKP.getValue())) {
            return KeyType.OKP;
        }
        return new KeyType(s, null);
    }
    
    public static KeyType forAlgorithm(final Algorithm alg) {
        if (alg == null) {
            return null;
        }
        if (JWSAlgorithm.Family.RSA.contains(alg)) {
            return KeyType.RSA;
        }
        if (JWSAlgorithm.Family.EC.contains(alg)) {
            return KeyType.EC;
        }
        if (JWSAlgorithm.Family.HMAC_SHA.contains(alg)) {
            return KeyType.OCT;
        }
        if (JWEAlgorithm.Family.RSA.contains(alg)) {
            return KeyType.RSA;
        }
        if (JWEAlgorithm.Family.ECDH_ES.contains(alg)) {
            return KeyType.EC;
        }
        if (JWEAlgorithm.DIR.equals(alg)) {
            return KeyType.OCT;
        }
        if (JWEAlgorithm.Family.AES_GCM_KW.contains(alg)) {
            return KeyType.OCT;
        }
        if (JWEAlgorithm.Family.AES_KW.contains(alg)) {
            return KeyType.OCT;
        }
        if (JWEAlgorithm.Family.PBES2.contains(alg)) {
            return KeyType.OCT;
        }
        if (JWSAlgorithm.Family.ED.contains(alg)) {
            return KeyType.OKP;
        }
        return null;
    }
    
    static {
        EC = new KeyType("EC", Requirement.RECOMMENDED);
        RSA = new KeyType("RSA", Requirement.REQUIRED);
        OCT = new KeyType("oct", Requirement.OPTIONAL);
        OKP = new KeyType("OKP", Requirement.OPTIONAL);
    }
}
