OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_HASH_VALUE_H_ | 5 #ifndef NET_BASE_HASH_VALUE_H_ |
6 #define NET_BASE_HASH_VALUE_H_ | 6 #define NET_BASE_HASH_VALUE_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 private: | 78 private: |
79 union { | 79 union { |
80 SHA1HashValue sha1; | 80 SHA1HashValue sha1; |
81 SHA256HashValue sha256; | 81 SHA256HashValue sha256; |
82 } fingerprint; | 82 } fingerprint; |
83 }; | 83 }; |
84 | 84 |
85 typedef std::vector<HashValue> HashValueVector; | 85 typedef std::vector<HashValue> HashValueVector; |
86 | 86 |
87 | |
88 class SHA1HashValueLessThan { | 87 class SHA1HashValueLessThan { |
89 public: | 88 public: |
90 bool operator()(const SHA1HashValue& lhs, | 89 bool operator()(const SHA1HashValue& lhs, const SHA1HashValue& rhs) const { |
91 const SHA1HashValue& rhs) const { | |
92 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0; | 90 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0; |
93 } | 91 } |
94 }; | 92 }; |
95 | 93 |
96 class SHA256HashValueLessThan { | 94 class SHA256HashValueLessThan { |
97 public: | 95 public: |
98 bool operator()(const SHA256HashValue& lhs, | 96 bool operator()(const SHA256HashValue& lhs, |
99 const SHA256HashValue& rhs) const { | 97 const SHA256HashValue& rhs) const { |
100 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0; | 98 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0; |
101 } | 99 } |
102 }; | 100 }; |
103 | 101 |
104 class HashValuesEqual { | 102 class HashValuesEqual { |
105 public: | 103 public: |
106 explicit HashValuesEqual(const HashValue& fingerprint) : | 104 explicit HashValuesEqual(const HashValue& fingerprint) |
107 fingerprint_(fingerprint) {} | 105 : fingerprint_(fingerprint) {} |
108 | 106 |
109 bool operator()(const HashValue& other) const { | 107 bool operator()(const HashValue& other) const { |
110 return fingerprint_.Equals(other); | 108 return fingerprint_.Equals(other); |
111 } | 109 } |
112 | 110 |
113 const HashValue& fingerprint_; | 111 const HashValue& fingerprint_; |
114 }; | 112 }; |
115 | 113 |
116 | |
117 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted | 114 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted |
118 // array of SHA1 hashes. | 115 // array of SHA1 hashes. |
119 bool IsSHA1HashInSortedArray(const SHA1HashValue& hash, | 116 bool IsSHA1HashInSortedArray(const SHA1HashValue& hash, |
120 const uint8* array, | 117 const uint8* array, |
121 size_t array_byte_len); | 118 size_t array_byte_len); |
122 | 119 |
123 } // namespace net | 120 } // namespace net |
124 | 121 |
125 #endif // NET_BASE_HASH_VALUE_H_ | 122 #endif // NET_BASE_HASH_VALUE_H_ |
OLD | NEW |