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

package com.google.crypto.tink.jwt;

import java.security.GeneralSecurityException;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Optional;
import com.google.crypto.tink.internal.EllipticCurvesUtil;
import java.security.spec.ECParameterSpec;
import com.google.errorprone.annotations.Immutable;
import java.util.Objects;

public final class JwtEcdsaParameters extends JwtSignatureParameters
{
    private final KidStrategy kidStrategy;
    private final Algorithm algorithm;
    
    public static Builder builder() {
        return new Builder();
    }
    
    private JwtEcdsaParameters(final KidStrategy kidStrategy, final Algorithm algorithm) {
        this.kidStrategy = kidStrategy;
        this.algorithm = algorithm;
    }
    
    public KidStrategy getKidStrategy() {
        return this.kidStrategy;
    }
    
    public Algorithm getAlgorithm() {
        return this.algorithm;
    }
    
    @Override
    public boolean hasIdRequirement() {
        return this.kidStrategy.equals(KidStrategy.BASE64_ENCODED_KEY_ID);
    }
    
    @Override
    public boolean allowKidAbsent() {
        return this.kidStrategy.equals(KidStrategy.CUSTOM) || this.kidStrategy.equals(KidStrategy.IGNORED);
    }
    
    @Override
    public boolean equals(final Object o) {
        if (!(o instanceof JwtEcdsaParameters)) {
            return false;
        }
        final JwtEcdsaParameters that = (JwtEcdsaParameters)o;
        return that.kidStrategy.equals(this.kidStrategy) && that.algorithm.equals(this.algorithm);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(JwtEcdsaParameters.class, this.kidStrategy, this.algorithm);
    }
    
    @Override
    public String toString() {
        return "JWT ECDSA Parameters (kidStrategy: " + this.kidStrategy + ", Algorithm " + this.algorithm + ")";
    }
    
    @Immutable
    public static final class KidStrategy
    {
        public static final KidStrategy BASE64_ENCODED_KEY_ID;
        public static final KidStrategy IGNORED;
        public static final KidStrategy CUSTOM;
        private final String name;
        
        private KidStrategy(final String name) {
            this.name = name;
        }
        
        @Override
        public String toString() {
            return this.name;
        }
        
        static {
            BASE64_ENCODED_KEY_ID = new KidStrategy("BASE64_ENCODED_KEY_ID");
            IGNORED = new KidStrategy("IGNORED");
            CUSTOM = new KidStrategy("CUSTOM");
        }
    }
    
    @Immutable
    public static final class Algorithm
    {
        public static final Algorithm ES256;
        public static final Algorithm ES384;
        public static final Algorithm ES512;
        private final String name;
        private final ECParameterSpec ecParameterSpec;
        
        private Algorithm(final String name, final ECParameterSpec ecParameterSpec) {
            this.name = name;
            this.ecParameterSpec = ecParameterSpec;
        }
        
        @Override
        public String toString() {
            return this.name;
        }
        
        public String getStandardName() {
            return this.name;
        }
        
        public ECParameterSpec getEcParameterSpec() {
            return this.ecParameterSpec;
        }
        
        static {
            ES256 = new Algorithm("ES256", EllipticCurvesUtil.NIST_P256_PARAMS);
            ES384 = new Algorithm("ES384", EllipticCurvesUtil.NIST_P384_PARAMS);
            ES512 = new Algorithm("ES512", EllipticCurvesUtil.NIST_P521_PARAMS);
        }
    }
    
    public static final class Builder
    {
        Optional<KidStrategy> kidStrategy;
        Optional<Algorithm> algorithm;
        
        @CanIgnoreReturnValue
        public Builder setKidStrategy(final KidStrategy kidStrategy) {
            this.kidStrategy = Optional.of(kidStrategy);
            return this;
        }
        
        @CanIgnoreReturnValue
        public Builder setAlgorithm(final Algorithm algorithm) {
            this.algorithm = Optional.of(algorithm);
            return this;
        }
        
        public JwtEcdsaParameters build() throws GeneralSecurityException {
            if (!this.algorithm.isPresent()) {
                throw new GeneralSecurityException("Algorithm must be set");
            }
            if (!this.kidStrategy.isPresent()) {
                throw new GeneralSecurityException("KidStrategy must be set");
            }
            return new JwtEcdsaParameters(this.kidStrategy.get(), this.algorithm.get(), null);
        }
        
        private Builder() {
            this.kidStrategy = Optional.empty();
            this.algorithm = Optional.empty();
        }
    }
}
