package common.packet;

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

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

public class RPacketRequestEncrypt implements Packet<IClientLoginHandler> {
	private PublicKey key;
	private PublicKey tempKey;

	public RPacketRequestEncrypt() {
	}

	public RPacketRequestEncrypt(PublicKey key, PublicKey tempKey) {
		this.key = key;
		this.tempKey = tempKey;
	}

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

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

	public void processPacket(IClientLoginHandler handler) {
		handler.handleEncrypt(this);
	}

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

	public PublicKey getTempKey() {
		return this.tempKey;
	}
}
