netwerk/cache2/CacheHashUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cache2/CacheHashUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef CacheHashUtils__h__
     1.9 +#define CacheHashUtils__h__
    1.10 +
    1.11 +#include "nsISupports.h"
    1.12 +#include "mozilla/Types.h"
    1.13 +#include "prnetdb.h"
    1.14 +#include "nsPrintfCString.h"
    1.15 +
    1.16 +#define LOGSHA1(x) \
    1.17 +    PR_htonl((reinterpret_cast<const uint32_t *>(x))[0]), \
    1.18 +    PR_htonl((reinterpret_cast<const uint32_t *>(x))[1]), \
    1.19 +    PR_htonl((reinterpret_cast<const uint32_t *>(x))[2]), \
    1.20 +    PR_htonl((reinterpret_cast<const uint32_t *>(x))[3]), \
    1.21 +    PR_htonl((reinterpret_cast<const uint32_t *>(x))[4])
    1.22 +
    1.23 +#define SHA1STRING(x) \
    1.24 +    (nsPrintfCString("%08x%08x%08x%08x%08x", LOGSHA1(x)).get())
    1.25 +
    1.26 +namespace mozilla {
    1.27 +namespace net {
    1.28 +
    1.29 +class CacheHash : public nsISupports
    1.30 +{
    1.31 +public:
    1.32 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.33 +
    1.34 +  typedef uint16_t Hash16_t;
    1.35 +  typedef uint32_t Hash32_t;
    1.36 +
    1.37 +  static Hash32_t Hash(const char* aData, uint32_t aSize, uint32_t aInitval=0);
    1.38 +  static Hash16_t Hash16(const char* aData, uint32_t aSize,
    1.39 +                         uint32_t aInitval=0);
    1.40 +
    1.41 +  CacheHash(uint32_t aInitval=0);
    1.42 +
    1.43 +  void     Update(const char *aData, uint32_t aLen);
    1.44 +  Hash32_t GetHash();
    1.45 +  Hash16_t GetHash16();
    1.46 +
    1.47 +private:
    1.48 +  virtual ~CacheHash() {}
    1.49 +
    1.50 +  void Feed(uint32_t aVal, uint8_t aLen = 4);
    1.51 +
    1.52 +  uint32_t mA, mB, mC;
    1.53 +  uint8_t  mPos;
    1.54 +  uint32_t mBuf;
    1.55 +  uint8_t  mBufPos;
    1.56 +  uint32_t mLength;
    1.57 +  bool     mFinalized;
    1.58 +};
    1.59 +
    1.60 +
    1.61 +} // net
    1.62 +} // mozilla
    1.63 +
    1.64 +#endif

mercurial