Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/cache2/CacheHashUtils.h
Line
Count
Source (jump to first uncovered line)
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/. */
4
5
#ifndef CacheHashUtils__h__
6
#define CacheHashUtils__h__
7
8
#include "nsISupports.h"
9
#include "mozilla/Types.h"
10
#include "prnetdb.h"
11
#include "nsPrintfCString.h"
12
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])
19
20
#define SHA1STRING(x) \
21
    (nsPrintfCString("%08x%08x%08x%08x%08x", LOGSHA1(x)).get())
22
23
namespace mozilla {
24
25
class OriginAttributes;
26
27
namespace net {
28
29
class CacheHash : public nsISupports
30
{
31
public:
32
  NS_DECL_THREADSAFE_ISUPPORTS
33
34
  typedef uint16_t Hash16_t;
35
  typedef uint32_t Hash32_t;
36
37
  static Hash32_t Hash(const char* aData, uint32_t aSize, uint32_t aInitval=0);
38
  static Hash16_t Hash16(const char* aData, uint32_t aSize,
39
                         uint32_t aInitval=0);
40
41
  explicit CacheHash(uint32_t aInitval=0);
42
43
  void     Update(const char *aData, uint32_t aLen);
44
  Hash32_t GetHash();
45
  Hash16_t GetHash16();
46
47
private:
48
0
  virtual ~CacheHash() = default;
49
50
  void Feed(uint32_t aVal, uint8_t aLen = 4);
51
52
  uint32_t mA, mB, mC;
53
  uint8_t  mPos;
54
  uint32_t mBuf;
55
  uint8_t  mBufPos;
56
  uint32_t mLength;
57
  bool     mFinalized;
58
};
59
60
typedef uint64_t OriginAttrsHash;
61
62
OriginAttrsHash GetOriginAttrsHash(const mozilla::OriginAttributes &aOA);
63
64
} // namespace net
65
} // namespace mozilla
66
67
#endif