package common.network;

import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.ShortBufferException;

import common.net.buffer.ByteBuf;
import common.net.channel.ChannelHandlerContext;
import common.net.handler.codec.MessageToMessageDecoder;

public class EncryptionDecoder extends MessageToMessageDecoder<ByteBuf> {
	private final EncryptionCodec codec;

	public EncryptionDecoder(Cipher cipher) {
		this.codec = new EncryptionCodec(cipher);
	}

	protected void decode(ChannelHandlerContext context, ByteBuf buffer, List<Object> output) throws ShortBufferException, Exception {
		output.add(this.codec.decipher(context, buffer));
	}
}
