package aalg.crypto;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import aalg.algebra.IElement;
import aalg.algebra.IGroup;

/**
 * Public key in discrete logarithm cryptosystems.
 * @author Ing. Petr Ležák
 */
public class DlPublicKey<T extends IElement> implements IPublicKey {
	
	private final T key;
	
	public DlPublicKey (final T key) {
		this.key = key;
	}

	public T getKey() {
		return key;
	}
	
	public static <T extends IElement> DlPublicKey<T> readFromStream (final IGroup<T> group, final InputStream stream) throws IOException {
		final T key = group.readElement(stream);
		
		return new DlPublicKey<T>(key);
	}
	
	public void writeToStream (final IGroup<T> group, final OutputStream stream) throws IOException {
		group.writeElement(key, stream);
	}
}
