michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef CacheHashUtils__h__ michael@0: #define CacheHashUtils__h__ michael@0: michael@0: #include "nsISupports.h" michael@0: #include "mozilla/Types.h" michael@0: #include "prnetdb.h" michael@0: #include "nsPrintfCString.h" michael@0: michael@0: #define LOGSHA1(x) \ michael@0: PR_htonl((reinterpret_cast(x))[0]), \ michael@0: PR_htonl((reinterpret_cast(x))[1]), \ michael@0: PR_htonl((reinterpret_cast(x))[2]), \ michael@0: PR_htonl((reinterpret_cast(x))[3]), \ michael@0: PR_htonl((reinterpret_cast(x))[4]) michael@0: michael@0: #define SHA1STRING(x) \ michael@0: (nsPrintfCString("%08x%08x%08x%08x%08x", LOGSHA1(x)).get()) michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: class CacheHash : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: typedef uint16_t Hash16_t; michael@0: typedef uint32_t Hash32_t; michael@0: michael@0: static Hash32_t Hash(const char* aData, uint32_t aSize, uint32_t aInitval=0); michael@0: static Hash16_t Hash16(const char* aData, uint32_t aSize, michael@0: uint32_t aInitval=0); michael@0: michael@0: CacheHash(uint32_t aInitval=0); michael@0: michael@0: void Update(const char *aData, uint32_t aLen); michael@0: Hash32_t GetHash(); michael@0: Hash16_t GetHash16(); michael@0: michael@0: private: michael@0: virtual ~CacheHash() {} michael@0: michael@0: void Feed(uint32_t aVal, uint8_t aLen = 4); michael@0: michael@0: uint32_t mA, mB, mC; michael@0: uint8_t mPos; michael@0: uint32_t mBuf; michael@0: uint8_t mBufPos; michael@0: uint32_t mLength; michael@0: bool mFinalized; michael@0: }; michael@0: michael@0: michael@0: } // net michael@0: } // mozilla michael@0: michael@0: #endif