Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef CacheHashUtils__h__ |
michael@0 | 6 | #define CacheHashUtils__h__ |
michael@0 | 7 | |
michael@0 | 8 | #include "nsISupports.h" |
michael@0 | 9 | #include "mozilla/Types.h" |
michael@0 | 10 | #include "prnetdb.h" |
michael@0 | 11 | #include "nsPrintfCString.h" |
michael@0 | 12 | |
michael@0 | 13 | #define LOGSHA1(x) \ |
michael@0 | 14 | PR_htonl((reinterpret_cast<const uint32_t *>(x))[0]), \ |
michael@0 | 15 | PR_htonl((reinterpret_cast<const uint32_t *>(x))[1]), \ |
michael@0 | 16 | PR_htonl((reinterpret_cast<const uint32_t *>(x))[2]), \ |
michael@0 | 17 | PR_htonl((reinterpret_cast<const uint32_t *>(x))[3]), \ |
michael@0 | 18 | PR_htonl((reinterpret_cast<const uint32_t *>(x))[4]) |
michael@0 | 19 | |
michael@0 | 20 | #define SHA1STRING(x) \ |
michael@0 | 21 | (nsPrintfCString("%08x%08x%08x%08x%08x", LOGSHA1(x)).get()) |
michael@0 | 22 | |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | namespace net { |
michael@0 | 25 | |
michael@0 | 26 | class CacheHash : public nsISupports |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 30 | |
michael@0 | 31 | typedef uint16_t Hash16_t; |
michael@0 | 32 | typedef uint32_t Hash32_t; |
michael@0 | 33 | |
michael@0 | 34 | static Hash32_t Hash(const char* aData, uint32_t aSize, uint32_t aInitval=0); |
michael@0 | 35 | static Hash16_t Hash16(const char* aData, uint32_t aSize, |
michael@0 | 36 | uint32_t aInitval=0); |
michael@0 | 37 | |
michael@0 | 38 | CacheHash(uint32_t aInitval=0); |
michael@0 | 39 | |
michael@0 | 40 | void Update(const char *aData, uint32_t aLen); |
michael@0 | 41 | Hash32_t GetHash(); |
michael@0 | 42 | Hash16_t GetHash16(); |
michael@0 | 43 | |
michael@0 | 44 | private: |
michael@0 | 45 | virtual ~CacheHash() {} |
michael@0 | 46 | |
michael@0 | 47 | void Feed(uint32_t aVal, uint8_t aLen = 4); |
michael@0 | 48 | |
michael@0 | 49 | uint32_t mA, mB, mC; |
michael@0 | 50 | uint8_t mPos; |
michael@0 | 51 | uint32_t mBuf; |
michael@0 | 52 | uint8_t mBufPos; |
michael@0 | 53 | uint32_t mLength; |
michael@0 | 54 | bool mFinalized; |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | } // net |
michael@0 | 59 | } // mozilla |
michael@0 | 60 | |
michael@0 | 61 | #endif |