package aalgTest;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import aalg.crypto.IInputStreamFilter;
import aalg.crypto.IOutputStreamFilter;
import aalg.crypto.Pkcs7PaddingReader;
import aalg.crypto.Pkcs7PaddingWriter;

public class Pkcs7PaddingTest extends PipeTest {
	private static final int BLOCK_LENGTH = 16;
	
	@Override
	protected IInputStreamFilter getInputFilter(final ByteArrayInputStream inputStream) throws IOException {
		final Pkcs7PaddingReader reader = new Pkcs7PaddingReader();
		reader.initialize(inputStream, BLOCK_LENGTH);
		
		return reader;
	}

	protected void flushInputFilter(final IInputStreamFilter filter) throws IOException {
		((Pkcs7PaddingReader) filter).finish();
	}

	@Override
	protected IOutputStreamFilter getOutputFilter(final ByteArrayOutputStream outputStream) throws IOException {
		final Pkcs7PaddingWriter writer = new Pkcs7PaddingWriter();
		writer.initialize(outputStream, BLOCK_LENGTH);
		
		return writer;
	}
	
	protected void flushOutputFilter(final IOutputStreamFilter filter) throws IOException {
		((Pkcs7PaddingWriter) filter).finish();
	}

}
