#pragma once

#include "../common/common.h"

#include <string.h>

#include "pkistore.h"

class ProviderMicrosoft : public Provider{
public:
	ProviderMicrosoft();
	~ProviderMicrosoft(){};

public:
	Handle<Certificate> static getCert(Handle<std::string> hash, Handle<std::string> category);
	//Handle<CRL> static getCRL(Handle<std::string> hash, Handle<std::string> category);
	//Handle<Key> static getKey(Handle<Certificate> cert);

	static void addPkiObject(Handle<Certificate> cert, Handle<std::string> category, Handle<std::string> contName = new std::string(), int provType = NULL);
	static void deletePkiObject(Handle<Certificate> cert, Handle<std::string> category);

	//static void addPkiObject(Handle<CRL> crl, Handle<std::string> category);
	//static void deletePkiObject(Handle<CRL> crl, Handle<std::string> category);

	bool static hasPrivateKey(Handle<Certificate> cert);

private:
	Handle<std::string> static nameToStr(
		IN DWORD dwCertEncodingType,
		IN const CERT_NAME_BLOB *pName,
		IN DWORD dwStrType = CERT_SIMPLE_NAME_STR
		);

	void init();
	void enumCertificates(HCERTSTORE hCertStore, std::string *category);
	void enumCrls(HCERTSTORE hCertStore, std::string *category);
	Handle<PkiItem> objectToPKIItem(Handle<Certificate> cert);
	//Handle<PkiItem> objectToPKIItem(Handle<CRL> crl);

	bool static hasPrivateKey(PCCERT_CONTEXT pCertContext);

	int static char2int(char input);
	void static hex2bin(const char* src, char* target);
};

