00001 00021 #pragma once 00022 00023 #ifndef HASH_H 00024 #define HASH_H 00025 00026 #include "types.h" 00027 00029 template <class hashClass> 00030 class CHashContainer 00031 { 00032 public: 00034 static const CString CLASSNAME; 00035 00037 enum {DIGESTSIZE = hashClass::DIGESTSIZE, DIGESTSIZE32 = DIGESTSIZE >> 2}; 00038 00039 CHashContainer(const uint32* pHash = NULL); // Create a new hash container object from uint32 or null data. 00040 CHashContainer(const CHashContainer &cHash); // Create a new hash container object from CHashContainer or null data. 00041 CHashContainer(CFile &cFile, uint64 nOffset = 0, uint64 nLength = 0); // Create hash from file. 00042 CHashContainer(void *pData, uint32 nData, void *pSalt=NULL, uint32 nSalt=0); // Create hash from memory block 00043 ~CHashContainer(void); // Destroy the hash container. 00044 00045 bool operator== (const CHashContainer &cHash) const; // Equality operator 00046 bool operator!= (const CHashContainer &cHash) const; // Inequality operator 00047 CHashContainer<hashClass> &operator= (const uint32 *pHash); // Assign hash using a uint32 pointer. 00048 CHashContainer<hashClass> &operator= (const CHashContainer &cHash); // Assign hash using a CHashContainer object. (copy) 00049 CHashContainer<hashClass> &operator^= (const CHashContainer &cHash); // Self-Assignment Bitwise Hash XOR. 00050 CHashContainer<hashClass> operator^ (const CHashContainer &cHash) const; // Bitwise Hash XOR. 00051 CHashContainer<hashClass> &operator|= (const CHashContainer &cHash); // Self-Assignment Bitwise Hash OR. 00052 CHashContainer<hashClass> operator| (const CHashContainer &cHash) const; // Bitwise Hash OR. 00053 CHashContainer<hashClass> &operator&= (const CHashContainer &cHash); // Self-Assignment Bitwise Hash AND. 00054 CHashContainer<hashClass> operator& (const CHashContainer &cHash) const; // Bitwise Hash AND. 00055 CHashContainer<hashClass> &operator<<= (const uint16 nBits); // Self-Assignment Left Hash Shift. 00056 CHashContainer<hashClass> operator<< (const uint16 nBits) const; // Left Hash Shift. 00057 CHashContainer<hashClass> &operator>>= (const uint16 nBits); // Self-Assignment Right Hash Shift. 00058 CHashContainer<hashClass> operator>> (const uint16 nBits) const; // Right Hash Shift. 00059 //operator const CString (); 00060 //operator const LPCSTR (); 00061 uint8 Hash (void *pData, uint32 nData, void *pSalt=NULL, uint32 nSalt=0); // Hash memory block 00062 uint8 GetHash (uint32* pHash); // Extract hash from object to pointer. 00063 00065 static CString StaticAlgorithmName () {return hashClass::StaticAlgorithmName();} 00066 00069 uint32* GetHashPtr () {return containerHash;} 00070 00072 CString GetHashHex (); 00073 00075 static uint64 GetCCount () {return containerCount;} 00076 private: 00078 uint32 containerHash[DIGESTSIZE32]; 00079 00081 static volatile uint64 containerCount; 00082 00087 static hashClass m_Hash; 00088 00094 }; 00095 00096 template <class hashClass> 00097 const CString CHashContainer<hashClass>::CLASSNAME = CString("CHashContainer/") + StaticAlgorithmName(); 00098 00099 template <class hashClass> 00100 volatile uint64 CHashContainer<hashClass>::containerCount = 0; 00101 00102 template <class hashClass> 00103 hashClass CHashContainer<hashClass>::m_Hash = hashClass(); 00104 00105 //template <class hashClass> 00106 //CMutex CHashContainer<hashClass>::m_Mutex; 00107 00108 #include "hashcontainer.cpp" 00109 00110 #endif
1.3.4