#ifndef CADES_LAODER_H_INCLUDED
#define CADES_LAODER_H_INCLUDED

#include <cades.h>

class CadesLoader
{
public:
	CadesLoader();
	~CadesLoader();

	bool isCadesAvailable();

	typedef BOOL(WINAPI* pfnCadesMsgEnhanceSignature)(
		HCRYPTMSG hCryptMsg,
		DWORD dwSignatureIndex,
		PCADES_SIGN_PARA pCadesSignPara);

	typedef BOOL (WINAPI* pfnCadesMsgVerifySignature)(
		HCRYPTMSG hCryptMsg,
		DWORD dwSignatureIndex,
		PCADES_VERIFICATION_PARA pVerificationPara,
		PCADES_VERIFICATION_INFO* ppVerificationInfo);

	typedef BOOL (WINAPI* pfnCadesMsgIsType)(
		HCRYPTMSG hCryptMsg,
		DWORD dwSignatureIndex,
		DWORD dwCadesType,
		BOOL* pbResult);

	typedef BOOL (WINAPI* pfnCadesMsgGetRevocationValuesEx)(
		PCMSG_SIGNER_INFO pSignerInfo,
		PCADES_BLOB_ARRAY* ppCRLs,
		PCADES_BLOB_ARRAY* ppBasicOCSPResponses);

	typedef BOOL (WINAPI* pfnCadesMsgGetCertificateValuesEx)(
		PCMSG_SIGNER_INFO pSignerInfo,
		PCADES_BLOB_ARRAY* ppCertificates);

	typedef BOOL (WINAPI* pfnCadesMsgIsTypeEncoded)(
		DWORD dwEncodingType,
		PBYTE pbSignerInfo,
		DWORD cbSignerInfo,
		DWORD dwCadesType,
		BOOL* pbResult);

	typedef BOOL (WINAPI* pfnCadesFreeVerificationInfo)(
		PCADES_VERIFICATION_INFO pVerificationInfo);

	typedef BOOL (WINAPI* pfnCadesFreeBlobArray)(
		PCADES_BLOB_ARRAY pBlobArray);

	BOOL CadesMsgEnhanceSignature(
		HCRYPTMSG hCryptMsg,
		DWORD dwSignatureIndex,
		PCADES_SIGN_PARA pCadesSignPara);

	BOOL CadesMsgVerifySignature(
		HCRYPTMSG hCryptMsg,
		DWORD dwSignatureIndex,
		PCADES_VERIFICATION_PARA pVerificationPara,
		PCADES_VERIFICATION_INFO* ppVerificationInfo);

	BOOL CadesMsgIsType(
		HCRYPTMSG hCryptMsg,
		DWORD dwSignatureIndex,
		DWORD dwCadesType,
		BOOL* pbResult);

	BOOL WINAPI CadesMsgGetRevocationValuesEx(
		PCMSG_SIGNER_INFO pSignerInfo,
		PCADES_BLOB_ARRAY* ppCRLs,
		PCADES_BLOB_ARRAY* ppBasicOCSPResponses);

	BOOL WINAPI CadesMsgGetCertificateValuesEx(
		PCMSG_SIGNER_INFO pSignerInfo,
		PCADES_BLOB_ARRAY* ppCertificates);

	BOOL WINAPI CadesMsgIsTypeEncoded(
		DWORD dwEncodingType,
		PBYTE pbSignerInfo,
		DWORD cbSignerInfo,
		DWORD dwCadesType,
		BOOL* pbResult);

	BOOL WINAPI CadesFreeVerificationInfo(
		PCADES_VERIFICATION_INFO pVerificationInfo);

	BOOL WINAPI CadesFreeBlobArray(
		PCADES_BLOB_ARRAY pBlobArray);

protected:
#ifdef _WIN32
	HMODULE m_hCadesLibrary;
#else
	void *m_pCadesLibrary;
#endif //_WIN32

	pfnCadesMsgEnhanceSignature m_pfnCadesMsgEnhanceSignature;
	pfnCadesMsgVerifySignature m_pfnCadesMsgVerifySignature;
	pfnCadesMsgIsType m_pfnCadesMsgIsType;
	pfnCadesMsgGetRevocationValuesEx m_pfnCadesMsgGetRevocationValuesEx;
	pfnCadesMsgGetCertificateValuesEx m_pfnCadesMsgGetCertificateValuesEx;
	pfnCadesMsgIsTypeEncoded m_pfnCadesMsgIsTypeEncoded;
	pfnCadesFreeVerificationInfo m_pfnCadesFreeVerificationInfo;
	pfnCadesFreeBlobArray m_pfnCadesFreeBlobArray;
};

#endif //!CADES_LAODER_H_INCLUDED
