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

package com.google.crypto.tink.aead;

import com.google.crypto.tink.subtle.XChaCha20Poly1305;
import com.google.crypto.tink.aead.internal.XChaCha20Poly1305Jce;
import com.google.crypto.tink.subtle.ChaCha20Poly1305;
import com.google.crypto.tink.aead.internal.ChaCha20Poly1305Jce;
import com.google.crypto.tink.config.internal.TinkFipsUtil;
import com.google.crypto.tink.Configuration;
import java.security.GeneralSecurityException;
import com.google.crypto.tink.aead.internal.XAesGcm;
import com.google.crypto.tink.subtle.AesEaxJce;
import com.google.crypto.tink.aead.subtle.AesGcmSiv;
import com.google.crypto.tink.subtle.AesGcmJce;
import com.google.crypto.tink.Key;
import com.google.crypto.tink.internal.PrimitiveConstructor;
import com.google.crypto.tink.Aead;
import com.google.crypto.tink.subtle.EncryptThenAuthenticate;
import com.google.crypto.tink.internal.PrimitiveRegistry;
import com.google.crypto.tink.internal.InternalConfiguration;

class AeadConfigurationV0
{
    private static final InternalConfiguration INTERNAL_CONFIGURATION;
    
    private AeadConfigurationV0() {
    }
    
    private static InternalConfiguration create() {
        try {
            final PrimitiveRegistry.Builder builder = PrimitiveRegistry.builder();
            AeadWrapper.registerToInternalPrimitiveRegistry(builder);
            builder.registerPrimitiveConstructor((PrimitiveConstructor<Key, Object>)PrimitiveConstructor.create((PrimitiveConstructor.PrimitiveConstructionFunction<KeyT, PrimitiveT>)EncryptThenAuthenticate::create, (Class<KeyT>)AesCtrHmacAeadKey.class, (Class<PrimitiveT>)Aead.class));
            builder.registerPrimitiveConstructor((PrimitiveConstructor<Key, Object>)PrimitiveConstructor.create((PrimitiveConstructor.PrimitiveConstructionFunction<KeyT, PrimitiveT>)AesGcmJce::create, (Class<KeyT>)AesGcmKey.class, (Class<PrimitiveT>)Aead.class));
            builder.registerPrimitiveConstructor((PrimitiveConstructor<Key, Object>)PrimitiveConstructor.create((PrimitiveConstructor.PrimitiveConstructionFunction<KeyT, PrimitiveT>)AesGcmSiv::create, (Class<KeyT>)AesGcmSivKey.class, (Class<PrimitiveT>)Aead.class));
            builder.registerPrimitiveConstructor((PrimitiveConstructor<Key, Object>)PrimitiveConstructor.create((PrimitiveConstructor.PrimitiveConstructionFunction<KeyT, PrimitiveT>)AesEaxJce::create, (Class<KeyT>)AesEaxKey.class, (Class<PrimitiveT>)Aead.class));
            builder.registerPrimitiveConstructor((PrimitiveConstructor<Key, Object>)PrimitiveConstructor.create((PrimitiveConstructor.PrimitiveConstructionFunction<KeyT, PrimitiveT>)AeadConfigurationV0::createChaCha20Poly1305, (Class<KeyT>)ChaCha20Poly1305Key.class, (Class<PrimitiveT>)Aead.class));
            builder.registerPrimitiveConstructor((PrimitiveConstructor<Key, Object>)PrimitiveConstructor.create((PrimitiveConstructor.PrimitiveConstructionFunction<KeyT, PrimitiveT>)AeadConfigurationV0::createXChaCha20Poly1305, (Class<KeyT>)XChaCha20Poly1305Key.class, (Class<PrimitiveT>)Aead.class));
            builder.registerPrimitiveConstructor((PrimitiveConstructor<Key, Object>)PrimitiveConstructor.create((PrimitiveConstructor.PrimitiveConstructionFunction<KeyT, PrimitiveT>)XAesGcm::create, (Class<KeyT>)XAesGcmKey.class, (Class<PrimitiveT>)Aead.class));
            return InternalConfiguration.createFromPrimitiveRegistry(builder.allowReparsingLegacyKeys().build());
        }
        catch (final GeneralSecurityException e) {
            throw new IllegalStateException(e);
        }
    }
    
    public static Configuration get() throws GeneralSecurityException {
        if (TinkFipsUtil.useOnlyFips()) {
            throw new GeneralSecurityException("Cannot use non-FIPS-compliant AeadConfigurationV0 in FIPS mode");
        }
        return AeadConfigurationV0.INTERNAL_CONFIGURATION;
    }
    
    private static Aead createChaCha20Poly1305(final ChaCha20Poly1305Key key) throws GeneralSecurityException {
        if (ChaCha20Poly1305Jce.isSupported()) {
            return ChaCha20Poly1305Jce.create(key);
        }
        return ChaCha20Poly1305.create(key);
    }
    
    private static Aead createXChaCha20Poly1305(final XChaCha20Poly1305Key key) throws GeneralSecurityException {
        if (XChaCha20Poly1305Jce.isSupported()) {
            return XChaCha20Poly1305Jce.create(key);
        }
        return XChaCha20Poly1305.create(key);
    }
    
    static {
        INTERNAL_CONFIGURATION = create();
    }
}
