#ifndef HashSHA0_class
#define HashSHA0_class

#include "Hash.h"
#include <openssl/sha.h>

using namespace std;


class HashSHA0 : public Hash {
	private :
		string key;
		SHA_CTX shaContext;
	public :
		HashSHA0();
		HashSHA0(string,string);
		~HashSHA0();
		virtual void Compute(string);
};

HashSHA0::HashSHA0(){
}


HashSHA0::HashSHA0(string p, string s){
	this->password=p;
	this->salt=s;
	this->hash="";
}

HashSHA0::~HashSHA0(){
}


void HashSHA0::Compute(string pass){
	unsigned char sha0_pw[21];
	SHA_Init(&shaContext);
	SHA_Update(&shaContext, (const unsigned char *)pass.c_str(), pass.length());
	SHA_Final((unsigned char *)sha0_pw, &shaContext);
	ostringstream oss;
	for(int i=0;i<=20;i++) oss << setfill ('0') << std::setw(2) << hex << static_cast<int>(sha0_pw[i]);
	this->hash=oss.str();
}


// the class factories
EXPORT Hash* create() {
    	return new HashSHA0;
}

EXPORT void destroy(Hash* p) {
	delete p;
}


#endif
