package aalg.crypto;

import aalg.algebra.IElement;
import aalg.algebra.SubGroupDefinition;

public class DHStreamCipher<T extends IElement> implements IStreamCipher, IAssymetricCipher<DlPrivateKey, DlPublicKey<T>> {
	
	private DlPublicKey<T> publicKey;
	private DlPrivateKey privateKey;
	private final IRandomGenerator rng;
	private final SubGroupDefinition<T> subGroupDefinition;
	private final IElementKeyExtractor<T> keyExtractor;
	private final ISymmetricStreamCipher cipher;


	public DHStreamCipher(final SubGroupDefinition<T> subGroupDefinition, final IRandomGenerator rng, final IElementKeyExtractor<T> keyExtractor, final ISymmetricStreamCipher cipher) {
		this.rng = rng;
		this.subGroupDefinition = subGroupDefinition;
		this.keyExtractor = keyExtractor;
		this.cipher = cipher;
	}
	
	@Override
	public IStreamEncryptor getEncryptor() {
		return new DHStreamEncryptor<T>(subGroupDefinition, rng, keyExtractor, cipher, publicKey);
	}

	@Override
	public IStreamDecryptor getDecryptor() {
		return new DHStreamDecryptor<T>(subGroupDefinition, keyExtractor, cipher, privateKey);
	}
	
	public void setPrivateKey (final DlPrivateKey key) {
		this.privateKey = key;
	}
	
	public void setPublicKey (final DlPublicKey<T> key) {
		this.publicKey = key;
	}

}
