package common.packet;

import java.io.IOException;
import java.security.PublicKey;

import common.network.ILoginHandler;
import common.network.Packet;
import common.network.PacketBuffer;
import common.util.EncryptUtil;

public class LPacketStartEncrypt implements Packet<ILoginHandler> {
	private PublicKey key;

	public LPacketStartEncrypt() {
	}

	public LPacketStartEncrypt(PublicKey pubkey) {
		this.key = pubkey;
	}

	public void readPacketData(PacketBuffer buf) throws IOException {
		this.key = EncryptUtil.decodeDHPublicKey(buf.readByteArray());
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		buf.writeByteArray(this.key.getEncoded());
	}

	public void processPacket(ILoginHandler handler) {
		handler.processEncryption(this);
	}

	public PublicKey getKey() {
		return this.key;
	}
}
