1 /* This file is part of pr-downloader (GPL v2 or later), see the LICENSE file */
2 
3 #ifndef _CCHECKSUM_H
4 #define _CCHECKSUM_H
5 
6 #include <string>
7 #include <assert.h>
8 
9 class IHash
10 {
11 public:
12 	/**
13 	*	Init Hash
14 	*/
15 	virtual void Init()=0;
16     /**
17     * abstract base classes should always have virtual dtors
18     */
~IHash()19     virtual ~IHash(){}
20 	/**
21 	*	Finalize Hash
22 	*/
23 	virtual void Final()=0;
24 	/**
25 	*	Update Hash with given data
26 	*/
27 	virtual void Update(const char* data,const int size)=0;
28 	/**
29 	*	return human readable hash string
30 	*/
31 	virtual const std::string toString(const unsigned char* data=NULL, int size=0);
32 	/**
33 	*	compare this hash
34 	*	@return true, when both hashes are identical
35 	*/
36 	virtual bool compare(const IHash* checksum);
37 	/**
38 	*	compare this hash
39 	*	@return true, when both hashes are identical
40 	*/
41 	virtual bool compare(const unsigned char* data, int size);
42 	/**
43 	* Set the md5 hash
44 	*/
45 	virtual bool Set(const unsigned char* data, int size)=0;
46 
47 	virtual bool Set(const std::string& hash);
48 	/**
49 	*	returns the size of binary hash for comparison
50 	*/
51 	virtual int getSize() const=0;
52 	/**
53 	*	returns true, if a hash is set/calculated
54 	*/
55 	virtual bool isSet();
56 	/**
57 	*	@return part of binary hash store for comparison
58 	*/
59 	virtual unsigned char get(int pos) const=0;
60 protected:
61 	bool isset;
62 private:
63 	/**
64 	* convert hex to int
65 	*/
66 	unsigned getVal(char c);
67 
68 };
69 
70 #endif
71