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

package com.google.crypto.tink.streamingaead.internal;

import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SeekableByteChannel;
import java.io.IOException;
import java.nio.channels.WritableByteChannel;
import java.security.GeneralSecurityException;
import com.google.crypto.tink.KeyManager;
import com.google.crypto.tink.internal.ProtoKeySerialization;
import com.google.crypto.tink.internal.KeyManagerRegistry;
import com.google.crypto.tink.InsecureSecretKeyAccess;
import com.google.crypto.tink.internal.LegacyProtoKey;
import com.google.crypto.tink.StreamingAead;

public class LegacyFullStreamingAead implements StreamingAead
{
    private final StreamingAead rawStreamingAead;
    
    public static StreamingAead create(final LegacyProtoKey key) throws GeneralSecurityException {
        final ProtoKeySerialization protoKeySerialization = key.getSerialization(InsecureSecretKeyAccess.get());
        final KeyManager<StreamingAead> manager = KeyManagerRegistry.globalInstance().getKeyManager(protoKeySerialization.getTypeUrl(), StreamingAead.class);
        return manager.getPrimitive(protoKeySerialization.getValue());
    }
    
    private LegacyFullStreamingAead(final StreamingAead rawStreamingAead) {
        this.rawStreamingAead = rawStreamingAead;
    }
    
    @Override
    public WritableByteChannel newEncryptingChannel(final WritableByteChannel ciphertextDestination, final byte[] associatedData) throws GeneralSecurityException, IOException {
        return this.rawStreamingAead.newEncryptingChannel(ciphertextDestination, associatedData);
    }
    
    @Override
    public SeekableByteChannel newSeekableDecryptingChannel(final SeekableByteChannel ciphertextSource, final byte[] associatedData) throws GeneralSecurityException, IOException {
        return this.rawStreamingAead.newSeekableDecryptingChannel(ciphertextSource, associatedData);
    }
    
    @Override
    public ReadableByteChannel newDecryptingChannel(final ReadableByteChannel ciphertextSource, final byte[] associatedData) throws GeneralSecurityException, IOException {
        return this.rawStreamingAead.newDecryptingChannel(ciphertextSource, associatedData);
    }
    
    @Override
    public OutputStream newEncryptingStream(final OutputStream ciphertextDestination, final byte[] associatedData) throws GeneralSecurityException, IOException {
        return this.rawStreamingAead.newEncryptingStream(ciphertextDestination, associatedData);
    }
    
    @Override
    public InputStream newDecryptingStream(final InputStream ciphertextSource, final byte[] associatedData) throws GeneralSecurityException, IOException {
        return this.rawStreamingAead.newDecryptingStream(ciphertextSource, associatedData);
    }
}
