/*
   +----------------------------------------------------------------------+
   | Copyright (c) 2002-2005 J Smith <dark_panda@hushmail.com>            |
   | Crypto++ sources (not included) copyright (c) 1995-2003 Wei Dai      |
   +----------------------------------------------------------------------+
   | Check out COPYING for the exact license.                             |
   +----------------------------------------------------------------------+

$Id: jbase.h,v 1.7 2005/01/06 18:16:42 jay Exp $
*/

#ifndef __JBASE_H__
#define __JBASE_H__

#include <string>

#include "jhelpers.h"
#include "jconstants.h"
#include "jsink.h"

// Crypto++ headers...

#include "hex.h"

using namespace CryptoPP;

class JBase
{
	public:
		JBase();
	
		string getPlaintext(const bool hex = false) const;
		string getCiphertext(const bool hex = false) const;
		string getKey(const bool hex = false) const;
		unsigned int getKeylength() const;

		void setPlaintext(const string plaintext, const bool hex = false);
		void setCiphertext(const string ciphertext, const bool hex = false);
		unsigned int setKey(const string key, bool hex = false);
		unsigned int setKeylength(const unsigned int keylength);

		virtual unsigned int getDefaultKeylength() const = 0;
		virtual unsigned int getMaxKeylength() const = 0;
		virtual unsigned int getMinKeylength() const = 0;
		virtual unsigned int getMultKeylength() const = 0;
		virtual unsigned int getValidKeylength(const unsigned int keylength) const = 0;
		virtual unsigned int getBlockSize() const = 0;
		virtual enum Cipher getCipherType() const = 0;
		virtual string getCipherName() const = 0;

		virtual bool encrypt() = 0;
		virtual bool decrypt() = 0;

		virtual bool encryptPHPStream(php_stream* in, php_stream* out) = 0;
		virtual bool decryptPHPStream(php_stream* in, php_stream* out) = 0;

		/* These are deprecated. They were used before using php_streams. Use them
		   if you're using this code in something other than the cryptopp PHP
		   extension...
		virtual bool encryptFile(const string in, const string out) = 0;
		virtual bool decryptFile(const string in, const string out) = 0; */

	protected:
		string itsPlaintext;
		string itsCiphertext;
		string itsKey;

		unsigned int itsKeylength;
};

#define getKeyHex() getKey(true)
#define getKeyBin() getKey()

#define getPlaintextHex() getPlaintext(true)
#define getPlaintextBin() getPlaintext()

#define getCiphertextHex() getCiphertext(true)
#define getCiphertextBin() getCiphertext()

#endif
