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 #include "net/base/hash_value.h" | 5 #include "net/base/hash_value.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 | 25 |
26 bool SHA1HashValue::Equals(const SHA1HashValue& other) const { | 26 bool SHA1HashValue::Equals(const SHA1HashValue& other) const { |
27 return memcmp(data, other.data, sizeof(data)) == 0; | 27 return memcmp(data, other.data, sizeof(data)) == 0; |
28 } | 28 } |
29 | 29 |
30 bool SHA256HashValue::Equals(const SHA256HashValue& other) const { | 30 bool SHA256HashValue::Equals(const SHA256HashValue& other) const { |
31 return memcmp(data, other.data, sizeof(data)) == 0; | 31 return memcmp(data, other.data, sizeof(data)) == 0; |
32 } | 32 } |
33 | 33 |
| 34 HashValue::HashValue(const SHA1HashValue& hash) : HashValue(HASH_VALUE_SHA1) { |
| 35 fingerprint.sha1 = hash; |
| 36 } |
| 37 |
| 38 HashValue::HashValue(const SHA256HashValue& hash) |
| 39 : HashValue(HASH_VALUE_SHA256) { |
| 40 fingerprint.sha256 = hash; |
| 41 } |
| 42 |
34 bool HashValue::Equals(const HashValue& other) const { | 43 bool HashValue::Equals(const HashValue& other) const { |
35 if (tag != other.tag) | 44 if (tag != other.tag) |
36 return false; | 45 return false; |
37 switch (tag) { | 46 switch (tag) { |
38 case HASH_VALUE_SHA1: | 47 case HASH_VALUE_SHA1: |
39 return fingerprint.sha1.Equals(other.fingerprint.sha1); | 48 return fingerprint.sha1.Equals(other.fingerprint.sha1); |
40 case HASH_VALUE_SHA256: | 49 case HASH_VALUE_SHA256: |
41 return fingerprint.sha256.Equals(other.fingerprint.sha256); | 50 return fingerprint.sha256.Equals(other.fingerprint.sha256); |
42 default: | 51 default: |
43 NOTREACHED() << "Unknown HashValueTag " << tag; | 52 NOTREACHED() << "Unknown HashValueTag " << tag; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 bool IsSHA1HashInSortedArray(const SHA1HashValue& hash, | 123 bool IsSHA1HashInSortedArray(const SHA1HashValue& hash, |
115 const uint8_t* array, | 124 const uint8_t* array, |
116 size_t array_byte_len) { | 125 size_t array_byte_len) { |
117 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length); | 126 DCHECK_EQ(0u, array_byte_len % base::kSHA1Length); |
118 const size_t arraylen = array_byte_len / base::kSHA1Length; | 127 const size_t arraylen = array_byte_len / base::kSHA1Length; |
119 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length, | 128 return NULL != bsearch(hash.data, array, arraylen, base::kSHA1Length, |
120 CompareSHA1Hashes); | 129 CompareSHA1Hashes); |
121 } | 130 } |
122 | 131 |
123 } // namespace net | 132 } // namespace net |
OLD | NEW |