netwerk/cache2/CacheHashUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef CacheHashUtils__h__
     6 #define CacheHashUtils__h__
     8 #include "nsISupports.h"
     9 #include "mozilla/Types.h"
    10 #include "prnetdb.h"
    11 #include "nsPrintfCString.h"
    13 #define LOGSHA1(x) \
    14     PR_htonl((reinterpret_cast<const uint32_t *>(x))[0]), \
    15     PR_htonl((reinterpret_cast<const uint32_t *>(x))[1]), \
    16     PR_htonl((reinterpret_cast<const uint32_t *>(x))[2]), \
    17     PR_htonl((reinterpret_cast<const uint32_t *>(x))[3]), \
    18     PR_htonl((reinterpret_cast<const uint32_t *>(x))[4])
    20 #define SHA1STRING(x) \
    21     (nsPrintfCString("%08x%08x%08x%08x%08x", LOGSHA1(x)).get())
    23 namespace mozilla {
    24 namespace net {
    26 class CacheHash : public nsISupports
    27 {
    28 public:
    29   NS_DECL_THREADSAFE_ISUPPORTS
    31   typedef uint16_t Hash16_t;
    32   typedef uint32_t Hash32_t;
    34   static Hash32_t Hash(const char* aData, uint32_t aSize, uint32_t aInitval=0);
    35   static Hash16_t Hash16(const char* aData, uint32_t aSize,
    36                          uint32_t aInitval=0);
    38   CacheHash(uint32_t aInitval=0);
    40   void     Update(const char *aData, uint32_t aLen);
    41   Hash32_t GetHash();
    42   Hash16_t GetHash16();
    44 private:
    45   virtual ~CacheHash() {}
    47   void Feed(uint32_t aVal, uint8_t aLen = 4);
    49   uint32_t mA, mB, mC;
    50   uint8_t  mPos;
    51   uint32_t mBuf;
    52   uint8_t  mBufPos;
    53   uint32_t mLength;
    54   bool     mFinalized;
    55 };
    58 } // net
    59 } // mozilla
    61 #endif

mercurial