// Mech.cpp: implementation of the CMech class.
//
//////////////////////////////////////////////////////////////////////

//#include "stdafx.h"
#include "FNMT_P11.h"
#include "Mech.h"
#include "Mech_RSA_PKCS.h"
#include "Mech_SHA1_RSA_PKCS.h"

#if 0
{
CK_ULONG ulNumMechanism = 2;

CK_I_MECHANISM_TYPE_INFO g_ListaMecanismos[] =
{
	/*// CKM_RSA_PKCS_KEY_PAIR_GEN
	{CKM_RSA_PKCS_KEY_PAIR_GEN, 
	{RSA_KEY_BITS_MIN_SIZE, RSA_KEY_BITS_MAX_SIZE, CKF_HW|CKF_GENERATE_KEY_PAIR},
	new CMech_RSA_PKCS_KEY_PAIR_GEN()},//*/

	/*// CKM_RSA_X_509
	{CKM_RSA_X_509, 
	{RSA_KEY_BITS_MIN_SIZE, RSA_KEY_BITS_MAX_SIZE, CKF_HW|CKF_DECRYPT|CKF_SIGN},
	new CMech_RSA_X_X509()},//*/

	//CKM_SHA1_RSA_PKCS
	{CKM_SHA1_RSA_PKCS, 
	{RSA_KEY_BITS_MIN_SIZE, RSA_KEY_BITS_MAX_SIZE, CKF_SIGN|CKF_VERIFY},
	new CMech_SHA1_RSA_PKCS(RSA_KEY_BITS_MIN_SIZE, RSA_KEY_BITS_MAX_SIZE, 0)},//*/

	//CKM_RSA_PKCS
	{CKM_RSA_PKCS, 
	{RSA_KEY_BITS_MIN_SIZE, RSA_KEY_BITS_MAX_SIZE, CKF_HW|CKF_SIGN|CKF_VERIFY|CKF_DECRYPT},
	new CMech_RSA_PKCS(RSA_KEY_BITS_MIN_SIZE, RSA_KEY_BITS_MAX_SIZE, 0)//*/

	}
};
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMech::CMech()
{
	m_pPKCS11Object		= NULL;
	m_pParameter		= NULL;
	m_ulParameterLen	= 0;

	m_MechInfo.ulMinKeySize	= 0;
	m_MechInfo.ulMaxKeySize	= 0;
	m_MechInfo.flags		= 0;
}

CMech::~CMech()
{

}

byte CMech::GetKeyReference()
{
	return ((CPKCS11PrivateKeyObject *)m_pPKCS11Object)->GetKeyReference();
}

CK_ULONG CMech::GetKeyLen()
{
	return ((CPKCS11PrivateKeyObject *)m_pPKCS11Object)->GetKeyLen();
}

CK_BBOOL CMech::GetBoolean(CK_ATTRIBUTE_TYPE boolAttr)
{
	return ((CPKCS11PrivateKeyObject *)m_pPKCS11Object)->GetAttributeBool(boolAttr);
}

void CMech::AddPadding( byteBuffer &data, ulong ulPaddedDataLen )
{
	return;
}

void CMech::RemovePadding( byteBuffer & message )
{
	return;
}

void CMech::ConstructData( byteBuffer & data )
{
	return;
}

void CMech::ConstructDataUpdate( byteBuffer &data )
{
	// Método sólo soportado si es con algoritmo de relleno SHA-1
	return;
}

void CMech::ConstructDataFinal( byteBuffer &signature )
{
	// Método sólo soportado si es con algoritmo de relleno SHA-1
	return;
}

CK_RV CMech::SignInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

CK_RV CMech::SignUpdate(CK_BYTE_PTR pPart, CK_ULONG ulPartLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

CK_RV CMech::SignFinal(CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

CK_RV CMech::VerifyInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

CK_RV CMech::VerifyUpdate(CK_BYTE_PTR pPart, CK_ULONG ulPartLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

CK_RV CMech::VerifyFinal(CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

CK_RV CMech::DecryptInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

/*CK_RV CMech::Sign(CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

/*CK_RV CMech::Verify(CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

/*CK_RV CMech::Decrypt(CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDatalen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen)
{
	return CKR_MECHANISM_INVALID;

}//*/

/*CK_RV CMech::EncryptInit(CPKCS11Object *pObj11, CK_VOID_PTR pParameter, CK_ULONG ulParameterLen, Tarjeta *pTarjeta)
{
	return CKR_MECHANISM_INVALID;
}//*/

/*CK_RV CMech::Encrypt(CK_BYTE_PTR pData, CK_ULONG ulatalen, CK_BYTE_PTR pEncryptedData, CK_ULONG_PTR pulEncryptedDataLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

/*CK_RV CMech::DigestInit(CK_VOID_PTR pParameter, CK_ULONG ulParameterLen, Tarjeta *pTarjeta)
{
	return CKR_MECHANISM_INVALID;
}//*/

/*CK_RV CMech::Digest(CK_BYTE_PTR pData, CK_ULONG ulatalen, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen)
{
	return CKR_MECHANISM_INVALID;
}//*/

