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

package com.google.crypto.tink.aead;

import com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat;
import com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat;
import com.google.crypto.tink.proto.HmacParams;
import com.google.crypto.tink.proto.HmacKeyFormat;
import com.google.crypto.tink.proto.AesCtrParams;
import com.google.crypto.tink.proto.AesCtrKeyFormat;
import com.google.crypto.tink.proto.HashType;
import com.google.crypto.tink.proto.AesEaxParams;
import com.google.crypto.tink.proto.AesEaxKeyFormat;
import com.google.crypto.tink.proto.OutputPrefixType;
import com.google.crypto.tink.proto.AesGcmKeyFormat;
import com.google.crypto.tink.proto.KeyTemplate;

public final class AeadKeyTemplates
{
    public static final KeyTemplate AES128_GCM;
    public static final KeyTemplate AES256_GCM;
    public static final KeyTemplate AES128_EAX;
    public static final KeyTemplate AES256_EAX;
    public static final KeyTemplate AES128_CTR_HMAC_SHA256;
    public static final KeyTemplate AES256_CTR_HMAC_SHA256;
    public static final KeyTemplate CHACHA20_POLY1305;
    public static final KeyTemplate XCHACHA20_POLY1305;
    
    public static KeyTemplate createAesGcmKeyTemplate(final int keySize) {
        final AesGcmKeyFormat format = AesGcmKeyFormat.newBuilder().setKeySize(keySize).build();
        return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(AesGcmKeyManager.getKeyType()).setOutputPrefixType(OutputPrefixType.TINK).build();
    }
    
    public static KeyTemplate createAesEaxKeyTemplate(final int keySize, final int ivSize) {
        final AesEaxKeyFormat format = AesEaxKeyFormat.newBuilder().setKeySize(keySize).setParams(AesEaxParams.newBuilder().setIvSize(ivSize).build()).build();
        return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(AesEaxKeyManager.getKeyType()).setOutputPrefixType(OutputPrefixType.TINK).build();
    }
    
    public static KeyTemplate createAesCtrHmacAeadKeyTemplate(final int aesKeySize, final int ivSize, final int hmacKeySize, final int tagSize, final HashType hashType) {
        final AesCtrKeyFormat aesCtrKeyFormat = AesCtrKeyFormat.newBuilder().setParams(AesCtrParams.newBuilder().setIvSize(ivSize).build()).setKeySize(aesKeySize).build();
        final HmacKeyFormat hmacKeyFormat = HmacKeyFormat.newBuilder().setParams(HmacParams.newBuilder().setHash(hashType).setTagSize(tagSize).build()).setKeySize(hmacKeySize).build();
        final AesCtrHmacAeadKeyFormat format = AesCtrHmacAeadKeyFormat.newBuilder().setAesCtrKeyFormat(aesCtrKeyFormat).setHmacKeyFormat(hmacKeyFormat).build();
        return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(AesCtrHmacAeadKeyManager.getKeyType()).setOutputPrefixType(OutputPrefixType.TINK).build();
    }
    
    public static KeyTemplate createKmsEnvelopeAeadKeyTemplate(final String kekUri, final KeyTemplate dekTemplate) {
        final KmsEnvelopeAeadKeyFormat format = KmsEnvelopeAeadKeyFormat.newBuilder().setDekTemplate(dekTemplate).setKekUri(kekUri).build();
        return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(KmsEnvelopeAeadKeyManager.getKeyType()).setOutputPrefixType(OutputPrefixType.RAW).build();
    }
    
    private AeadKeyTemplates() {
    }
    
    static {
        AES128_GCM = createAesGcmKeyTemplate(16);
        AES256_GCM = createAesGcmKeyTemplate(32);
        AES128_EAX = createAesEaxKeyTemplate(16, 16);
        AES256_EAX = createAesEaxKeyTemplate(32, 16);
        AES128_CTR_HMAC_SHA256 = createAesCtrHmacAeadKeyTemplate(16, 16, 32, 16, HashType.SHA256);
        AES256_CTR_HMAC_SHA256 = createAesCtrHmacAeadKeyTemplate(32, 16, 32, 32, HashType.SHA256);
        CHACHA20_POLY1305 = KeyTemplate.newBuilder().setTypeUrl(ChaCha20Poly1305KeyManager.getKeyType()).setOutputPrefixType(OutputPrefixType.TINK).build();
        XCHACHA20_POLY1305 = KeyTemplate.newBuilder().setTypeUrl(XChaCha20Poly1305KeyManager.getKeyType()).setOutputPrefixType(OutputPrefixType.TINK).build();
    }
}
