///////////////////////////////////////////////////////////////////////////////
/// @file dePlugins.hpp
///
/// @brief base plugin header
///
/// @author Lightning
///
/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
/// contents of this file is subject to the Destiny3D Member License which
/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
///
/// This file is distributed "AS IS" without warranty of any kind.  Novus
/// Delta, LLC. does not guarantee the fitness of the contents of this file
/// for any particular purpose.
///
/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
///
/// <hr>
///                                 Change History
/// <hr>
///
/// @date Nov 2001
/// @author Lightning
/// @remarks Creation
///
///////////////////////////////////////////////////////////////////////////////

#ifndef DE_PLUGIN_HPP
#define DE_PLUGIN_HPP

#include "deGlobalTypes.hpp"

#if defined(DEPLUGINS_DLL_EXPORTS) || defined(DESTINY3D_EXPORT_ALL)
#	define DEPLUGIN_API extern "C" DEDLL_EXPORT
#elif defined(DESTINY3D_STATIC_LINK)
#	define DEPLUGIN_API extern "C"
#else
#	define DEPLUGIN_API extern "C" DEDLL_IMPORT
#endif

#ifdef USING_DESTINY3D
#ifdef _DEBUG
#	ifdef DESTINY3D_STATIC_LINK
#		pragma comment(lib, "dePlugins_sd")
#		pragma comment(lib, "zlib-d")
#	else
#		pragma comment(lib, "dePluginsd")
#	endif //DESTINY3D_STATIC_LINK
#else
#	ifdef DESTINY3D_STATIC_LINK
#		pragma comment(lib, "dePlugins_s")
#		pragma comment(lib, "zlib")
#	else
#		pragma comment(lib, "dePlugins")
#	endif //DESTINY3D_STATIC_LINK
#endif //_DEBUG
#endif //USING_DESTINY3D

//-------------------------------------------
// Classes Declared
//-------------------------------------------
class IdePlugin;
class IdePluginTwofish;
class IdePluginRijndael;
class IdePluginZLib;
class IdePluginSHA1;

//-------------------------------------------
// Factory functions
//-------------------------------------------
extern "C"
{
	DEPLUGIN_API IdePluginTwofish*	IdePlugin_CreateTwofish();
	DEPLUGIN_API IdePluginRijndael*	IdePlugin_CreateRijndael();
	DEPLUGIN_API IdePluginZLib*		IdePlugin_CreateZLib();
	DEPLUGIN_API IdePluginSHA1*		IdePlugin_CreateSHA1();
}

//the base class for plugins
//class IdePlugin
DE3D_INTERFACE_(IdePlugin)
{
	protected:
		virtual ~IdePlugin() {};
		
	public:
		enum interface_t
		{
			iface_IdePlugin = 0,
			iface_IdePluginTwofish,
			iface_IdePluginRijndael,
			iface_IdePluginZLib,
			iface_IdePluginSHA1,
			iface_force_32bit = 0x7FFFFFFF
		};

		//get the interface for a class
		virtual void* GetInterface(IdePlugin::interface_t i) = 0;

		//release a plugin
		virtual int Release() = 0;

		//the basic interface functions for the data manipulation
		//buffer/length = input
		//newbuffer/newlength = new output, newlength is set to the length of the new buffer
		//it is updated to the actual written length
		virtual deBoolean EncodeData(void *Buffer, DWORD Length, void *NewBuffer, DWORD *NewLength) = 0;
		virtual deBoolean DecodeData(void *Buffer, DWORD Length, void *NewBuffer, DWORD *NewLength) = 0;

		//get the maximum size needed for a buffer
		virtual DWORD MaxEncodeLength(DWORD Length) = 0;
		virtual DWORD MaxDecodeLength(void *Buffer) = 0;

		//other functions are likely to exist to set individual settings for a plugin
};

//class IdePluginTwofish : virtual public IdePlugin
DE3D_INTERFACE(IdePluginTwofish, IdePlugin)
{
	protected:
		~IdePluginTwofish() {};

	public:
		enum Mode
		{
			ECB = 1,
			CBC,
			CFB1,
		};

		//different settings that can be set
		virtual deBoolean SetKey(void *KeyBuffer, long Bitsize) = 0;	//what key to use
		virtual deBoolean SetIV(void *IVBuffer, long Length) = 0;		//what IV to use (used on CBC and CFB1)
		virtual deBoolean SetMode(Mode CipherMode) = 0;					//the type of encryption
		virtual deBoolean SetRounds(int NumberRounds) = 0;				//number of rounds to do
};

//class IdePluginRijndael : virtual public IdePlugin
DE3D_INTERFACE(IdePluginRijndael, IdePlugin)
{
	protected:
		~IdePluginRijndael() {};

	public:

		//different settings that can be set
		virtual deBoolean SetKey(void *KeyBuffer, long Bitsize) = 0;	//what key to use
		virtual deBoolean SetIV(void *IVBuffer, long Blocksize) = 0;	//IV to use
};

//class IdePluginZLib : virtual public IdePlugin
DE3D_INTERFACE(IdePluginZLib, IdePlugin)
{
	protected:
		~IdePluginZLib() {};

	public:
		enum DataType
		{
			BINARY = 0,
			ASCII = 1,
		};

		//different settings that can be set
		virtual deBoolean SetType(DataType Type) = 0;					//the type of data to compress
		virtual deBoolean SetCompressAmount(long Amount) = 0;			//how much to compress it (0-9)
};

//class IdePluginSHA1 : virtual public IdePlugin
DE3D_INTERFACE(IdePluginSHA1, IdePlugin)
{
	protected:
		~IdePluginSHA1() {};

	public:
};

#endif
