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

package com.google.crypto.tink.prf;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import javax.annotation.Nullable;
import com.google.errorprone.annotations.Immutable;
import java.util.Objects;

public final class HmacPrfParameters extends PrfParameters
{
    private static final int MIN_KEY_SIZE = 16;
    private final int keySizeBytes;
    private final HashType hashType;
    
    private HmacPrfParameters(final int keySizeBytes, final HashType hashType) {
        this.keySizeBytes = keySizeBytes;
        this.hashType = hashType;
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public int getKeySizeBytes() {
        return this.keySizeBytes;
    }
    
    public HashType getHashType() {
        return this.hashType;
    }
    
    @Override
    public boolean equals(final Object o) {
        if (!(o instanceof HmacPrfParameters)) {
            return false;
        }
        final HmacPrfParameters that = (HmacPrfParameters)o;
        return that.getKeySizeBytes() == this.getKeySizeBytes() && that.getHashType() == this.getHashType();
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(HmacPrfParameters.class, this.keySizeBytes, this.hashType);
    }
    
    @Override
    public boolean hasIdRequirement() {
        return false;
    }
    
    @Override
    public String toString() {
        return "HMAC PRF Parameters (hashType: " + this.hashType + " and " + this.keySizeBytes + "-byte key)";
    }
    
    @Immutable
    public static final class HashType
    {
        public static final HashType SHA1;
        public static final HashType SHA224;
        public static final HashType SHA256;
        public static final HashType SHA384;
        public static final HashType SHA512;
        private final String name;
        
        private HashType(final String name) {
            this.name = name;
        }
        
        @Override
        public String toString() {
            return this.name;
        }
        
        static {
            SHA1 = new HashType("SHA1");
            SHA224 = new HashType("SHA224");
            SHA256 = new HashType("SHA256");
            SHA384 = new HashType("SHA384");
            SHA512 = new HashType("SHA512");
        }
    }
    
    public static final class Builder
    {
        @Nullable
        private Integer keySizeBytes;
        @Nullable
        private HashType hashType;
        
        private Builder() {
            this.keySizeBytes = null;
            this.hashType = null;
        }
        
        @CanIgnoreReturnValue
        public Builder setKeySizeBytes(final int keySizeBytes) throws GeneralSecurityException {
            if (keySizeBytes < 16) {
                throw new InvalidAlgorithmParameterException(String.format("Invalid key size %d; only 128-bit or larger are supported", keySizeBytes * 8));
            }
            this.keySizeBytes = keySizeBytes;
            return this;
        }
        
        @CanIgnoreReturnValue
        public Builder setHashType(final HashType hashType) {
            this.hashType = hashType;
            return this;
        }
        
        public HmacPrfParameters build() throws GeneralSecurityException {
            if (this.keySizeBytes == null) {
                throw new GeneralSecurityException("key size is not set");
            }
            if (this.hashType == null) {
                throw new GeneralSecurityException("hash type is not set");
            }
            return new HmacPrfParameters(this.keySizeBytes, this.hashType, null);
        }
    }
}
