// Mech.h: interface for the CMech class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MECH_H__8E2152C5_D267_11D4_A93D_00105ACAACA9__INCLUDED_)
#define AFX_MECH_H__8E2152C5_D267_11D4_A93D_00105ACAACA9__INCLUDED_

#include "FNMT_P11.h"
#include "pkcs11t.h"	// Added by ClassView

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#define RSA_KEY_BITS_MIN_SIZE	1024
#define RSA_KEY_BITS_MAX_SIZE	2048


class CMech  
{
public:

	CK_MECHANISM_TYPE m_MechType;
	CK_MECHANISM_INFO m_MechInfo;

	// Método para devolver la clave sobre la que trabajar
	byte GetKeyReference();
	CK_ULONG GetKeyLen();

	CK_BBOOL GetBoolean(CK_ATTRIBUTE_TYPE boolAttr);

	virtual void AddPadding( byteBuffer &data, ulong ulPaddedDataLen );
	virtual void RemovePadding( byteBuffer & message );

	virtual void ConstructData( byteBuffer &data );

	virtual void ConstructDataUpdate( byteBuffer &data );
	virtual void ConstructDataFinal( byteBuffer &signature );

	virtual CK_RV SignInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen);
	virtual CK_RV SignUpdate(CK_BYTE_PTR pPart, CK_ULONG ulPartLen);
	virtual CK_RV SignFinal(CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen);
	
	virtual CK_RV VerifyInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen);
	virtual CK_RV VerifyUpdate(CK_BYTE_PTR pPart, CK_ULONG ulPartLen);
	virtual CK_RV VerifyFinal(CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen);

	virtual CK_RV DecryptInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen);

	/*virtual CK_RV DigestInit(CK_VOID_PTR pParameter, CK_ULONG ulParameterLen, Tarjeta *pTarjeta);
	virtual CK_RV Digest(CK_BYTE_PTR pData, CK_ULONG ulDatalen, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen);
	
	virtual CK_RV EncryptInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen, Tarjeta *pTarjeta);
	virtual CK_RV Encrypt(CK_BYTE_PTR pData, CK_ULONG ulDatalen, CK_BYTE_PTR pEncryptedData, CK_ULONG_PTR pulEncryptedDataLen);
	
	virtual CK_RV DecryptInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen, Tarjeta *pTarjeta);
	virtual CK_RV Decrypt(CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDatalen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen);*/
		
	CMech();
	virtual ~CMech();

protected:
	CK_ULONG	m_ulParameterLen;
	void *		m_pParameter;
	CPKCS11Object * m_pPKCS11Object;

	SHA1		m_sha1;
};

#endif // !defined(AFX_MECH_H__8E2152C5_D267_11D4_A93D_00105ACAACA9__INCLUDED_)
