// 
// 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 com.google.errorprone.annotations.Immutable;
import java.util.Objects;
import javax.annotation.Nullable;
import com.google.crypto.tink.util.Bytes;

public final class HkdfPrfParameters extends PrfParameters
{
    private static final int MIN_KEY_SIZE = 16;
    private final int keySizeBytes;
    private final HashType hashType;
    @Nullable
    private final Bytes salt;
    
    private HkdfPrfParameters(final int keySizeBytes, final HashType hashType, final Bytes salt) {
        this.keySizeBytes = keySizeBytes;
        this.hashType = hashType;
        this.salt = salt;
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public int getKeySizeBytes() {
        return this.keySizeBytes;
    }
    
    public HashType getHashType() {
        return this.hashType;
    }
    
    @Nullable
    public Bytes getSalt() {
        return this.salt;
    }
    
    @Override
    public boolean equals(final Object o) {
        if (!(o instanceof HkdfPrfParameters)) {
            return false;
        }
        final HkdfPrfParameters that = (HkdfPrfParameters)o;
        return that.getKeySizeBytes() == this.getKeySizeBytes() && that.getHashType() == this.getHashType() && Objects.equals(that.getSalt(), this.getSalt());
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(HkdfPrfParameters.class, this.keySizeBytes, this.hashType, this.salt);
    }
    
    @Override
    public boolean hasIdRequirement() {
        return false;
    }
    
    @Override
    public String toString() {
        return "HKDF PRF Parameters (hashType: " + this.hashType + ", salt: " + this.salt + ", 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;
        @Nullable
        private Bytes salt;
        
        private Builder() {
            this.keySizeBytes = null;
            this.hashType = null;
            this.salt = 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;
        }
        
        @CanIgnoreReturnValue
        public Builder setSalt(final Bytes salt) {
            if (salt.size() == 0) {
                this.salt = null;
                return this;
            }
            this.salt = salt;
            return this;
        }
        
        public HkdfPrfParameters 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 HkdfPrfParameters(this.keySizeBytes, this.hashType, this.salt, null);
        }
    }
}
