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 <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 return memcmp(a, b, base::kSHA1Length); | 23 return memcmp(a, b, base::kSHA1Length); |
24 } | 24 } |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 | 28 |
29 bool SHA1HashValue::Equals(const SHA1HashValue& other) const { | 29 bool SHA1HashValue::Equals(const SHA1HashValue& other) const { |
30 return memcmp(data, other.data, sizeof(data)) == 0; | 30 return memcmp(data, other.data, sizeof(data)) == 0; |
31 } | 31 } |
32 | 32 |
| 33 bool SHA1HashValue::Persist(base::Pickle* pickle) const { |
| 34 return pickle->WriteBytes(data, sizeof(data)); |
| 35 } |
| 36 |
| 37 bool SHA1HashValue::CreateFromPickle(base::PickleIterator* iter, |
| 38 SHA1HashValue* hash) { |
| 39 const char* outdata_char = NULL; |
| 40 if (!iter->ReadBytes(&outdata_char, sizeof(hash->data))) |
| 41 return false; |
| 42 memcpy(&hash->data, outdata_char, sizeof(hash->data)); |
| 43 return true; |
| 44 } |
| 45 |
33 bool SHA256HashValue::Equals(const SHA256HashValue& other) const { | 46 bool SHA256HashValue::Equals(const SHA256HashValue& other) const { |
34 return memcmp(data, other.data, sizeof(data)) == 0; | 47 return memcmp(data, other.data, sizeof(data)) == 0; |
35 } | 48 } |
36 | 49 |
37 HashValue::HashValue(const SHA1HashValue& hash) : HashValue(HASH_VALUE_SHA1) { | 50 HashValue::HashValue(const SHA1HashValue& hash) : HashValue(HASH_VALUE_SHA1) { |
38 fingerprint.sha1 = hash; | 51 fingerprint.sha1 = hash; |
39 } | 52 } |
40 | 53 |
41 HashValue::HashValue(const SHA256HashValue& hash) | 54 HashValue::HashValue(const SHA256HashValue& hash) |
42 : HashValue(HASH_VALUE_SHA256) { | 55 : HashValue(HASH_VALUE_SHA256) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 bool IsSHA256HashInSortedArray(const SHA256HashValue& hash, | 139 bool IsSHA256HashInSortedArray(const SHA256HashValue& hash, |
127 const uint8_t* array, | 140 const uint8_t* array, |
128 size_t array_byte_len) { | 141 size_t array_byte_len) { |
129 DCHECK_EQ(0u, array_byte_len % crypto::kSHA256Length); | 142 DCHECK_EQ(0u, array_byte_len % crypto::kSHA256Length); |
130 const size_t arraylen = array_byte_len / crypto::kSHA256Length; | 143 const size_t arraylen = array_byte_len / crypto::kSHA256Length; |
131 return NULL != bsearch(hash.data, array, arraylen, crypto::kSHA256Length, | 144 return NULL != bsearch(hash.data, array, arraylen, crypto::kSHA256Length, |
132 CompareSHA1Hashes); | 145 CompareSHA1Hashes); |
133 } | 146 } |
134 | 147 |
135 } // namespace net | 148 } // namespace net |
OLD | NEW |