#pragma once

#include <exception>
#include "cryptoki.h"
#include "Util.h"

using namespace std;


/********************************************************************************************
	Conjunto de excepciones propias.
********************************************************************************************/


// Excepción genérica del módulo PKCS#11.
class Pkcs11Exception: public exception
{
public:
	//
	// Constructores
	//
	Pkcs11Exception() : m_ckErr( CKR_GENERAL_ERROR ){};
	~Pkcs11Exception() throw()
	{
		DBG_TRACE(( "Destructor Pkcs11Exception [0x%08x]\n", this ));
	}
	Pkcs11Exception( CK_RV errId ) : m_ckErr( errId )
	{
		DBG_TRACE(( "Pkcs11Exception(0x%08x) [0x%08x]\n", errId, this ));
	};
#ifdef _DEBUG
	Pkcs11Exception( CK_RV errId, char * pFile, long line ) : m_ckErr( errId )
	{
		DBG_TRACE(( "Pkcs11Exception(0x%08x) en %s:%d, [0x%08x]\n", errId, pFile, line, this ));
	};
#endif
	//
	// Métodos
	//
	CK_RV		getErrId() { return m_ckErr; }
	void		setErrId(CK_RV err) { m_ckErr = err; }

protected:
	CK_RV		m_ckErr;
};


#ifdef _DEBUG
	#define	Pkcs11Exception(CODE)	Pkcs11Exception(CODE,(char *)__FILE__,__LINE__)
#endif
