#ifndef UTIL_HASH_INCLUDED
#define UTIL_HASH_INCLUDED

#include "wrapper/common/log.h"
#include "../common/common.h"
#include "utils/ihash.h"
#include "../pki/pki.h"

class Hash : public IHash
{
public:
	Hash();
	Hash(HashAlg::HASH_ALG hashAlg);
	~Hash();

	void addData(unsigned char *buf, size_t buflen);
	Handle<std::string> getValue();
	void setValue(Handle<std::string> hashVal);
	size_t getHashSize();

	operator HCRYPTHASH();
	HCRYPTPROV getProviderHandle();

	static Handle<std::string> hashData(HashAlg::HASH_ALG hashAlg, unsigned char *buf, size_t buflen);
	static Handle<std::string> hashFile(HashAlg::HASH_ALG hashAlg, Handle<std::string> fileName);

	static HashAlg::HASH_ALG hashAlgByOid(const char* hashAlgOid);
	static std::string hashOidByHashAlg(HashAlg::HASH_ALG enmAlg);
	static HashAlg::HASH_ALG hashAlgBySignatureAlg(const char* signOid);
	static Handle<std::string> hashAlgByKeyAlg(const char* signOid);

protected:
	HCRYPTPROV hProv;
	HCRYPTHASH hHash;
};

#endif //!UTIL_HASH_INCLUDED
