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

package com.google.crypto.tink.internal;

import com.google.crypto.tink.Parameters;
import java.security.GeneralSecurityException;
import com.google.crypto.tink.KeyTemplate;
import com.google.crypto.tink.proto.OutputPrefixType;

public final class KeyTemplateProtoConverter
{
    public static KeyTemplate.OutputPrefixType prefixFromProto(final OutputPrefixType outputPrefixType) throws GeneralSecurityException {
        switch (outputPrefixType) {
            case TINK: {
                return KeyTemplate.OutputPrefixType.TINK;
            }
            case LEGACY: {
                return KeyTemplate.OutputPrefixType.LEGACY;
            }
            case RAW: {
                return KeyTemplate.OutputPrefixType.RAW;
            }
            case CRUNCHY: {
                return KeyTemplate.OutputPrefixType.CRUNCHY;
            }
            default: {
                throw new GeneralSecurityException("Unknown output prefix type");
            }
        }
    }
    
    public static com.google.crypto.tink.proto.KeyTemplate toProto(final KeyTemplate keyTemplate) throws GeneralSecurityException {
        final Parameters parameters = keyTemplate.toParameters();
        if (parameters instanceof LegacyProtoParameters) {
            return ((LegacyProtoParameters)parameters).getSerialization().getKeyTemplate();
        }
        final ProtoParametersSerialization s = MutableSerializationRegistry.globalInstance().serializeParameters(parameters, ProtoParametersSerialization.class);
        return s.getKeyTemplate();
    }
    
    public static byte[] toByteArray(final KeyTemplate keyTemplate) throws GeneralSecurityException {
        return toProto(keyTemplate).toByteArray();
    }
    
    public static KeyTemplate.OutputPrefixType getOutputPrefixType(final KeyTemplate t) throws GeneralSecurityException {
        return prefixFromProto(toProto(t).getOutputPrefixType());
    }
    
    private KeyTemplateProtoConverter() {
    }
}
