#include "CharStream.h"
#include "Option.h"
//#include "TelnetEngine.h"


//#include "Negotiator.h"
//#include "KClient.h"

class CryptoEngine;

enum
{
		ENCRYPT_OPT		=		38,
	// ExecOption Commands
		ENCRYPT_ON		=		1,
		ENCRYPT_OFF		=		2
};

class EncryptOption : public Option{
public:
	EncryptOption(CharStream *stream, TelnetEngine *);
	~EncryptOption();
	
	void NegotiateOption(unsigned char);
	
	void ExecOption(unsigned int Command, void* Data = NULL);

private:
	void sendIS_NULL(void);
	void recievedSUPPORT ();
	void recievedREPLY ();
	void recievedIS();
	void recievedREQSTART ();
	void recievedREQEND ();
	void recievedDEC_KEYID ();
	void recievedENC_KEYID ();
	void recievedSTART();
	void recievedEND();
	void sendSUPPORT ();
	void sendREPLY (int answer);
	void sendIS();
	void sendREQSTART ();
	void sendREQEND ();
	void sendDEC_KEYID (int answer);
	void sendENC_KEYID ();
	void sendSTART();
	void sendEND();
	void sendEncrypt(int option); // DO, DONT, WILL, WONT
	BOOL			mReadyToEncrypt;
	int 			mDecKeyId;
	CryptoEngine*   pCryptoEngine;
	unsigned char	mDecIV[8];
	unsigned char	mEncIV[8];
	int				mIVCount;
	// Encryption options
	enum{
		IS				=		0,
		SUPPORT			=		1,
		REPLY			=		2,
		START			=		3,
		END				=		4,
		REQUEST_START	=		5,
	 	REQUEST_END		=		6,
		ENC_KEYID		=		7,
		DEC_KEYID		=		8,
		DEF_KEYID		=		0,	// Default
		
	#ifndef NULL
		NULL			=		0,
	#endif
		DES_CFB64		=		1,
		DES_OFB64		=		2,
	
	// CFB64 Suboption Commands
		CFB64_IV		= 		1,
	 	CFB64_IV_OK		=		2,
		CFB64_IV_BAD	=		3,
		CFB64_CHALLENGE	=		4,
		CFB64_RESPONSE	=		5,
	};
};