OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/user_prefs/tracked/pref_hash_calculator.h" | 5 #include "components/user_prefs/tracked/pref_hash_calculator.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
| 9 #include <memory> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "crypto/hmac.h" | 18 #include "crypto/hmac.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Calculates an HMAC of |message| using |key|, encoded as a hexadecimal string. | 22 // Calculates an HMAC of |message| using |key|, encoded as a hexadecimal string. |
23 std::string GetDigestString(const std::string& key, | 23 std::string GetDigestString(const std::string& key, |
24 const std::string& message) { | 24 const std::string& message) { |
(...skipping 19 matching lines...) Expand all Loading... |
44 digest.size())); | 44 digest.size())); |
45 } | 45 } |
46 | 46 |
47 // Renders |value| as a string. |value| may be NULL, in which case the result | 47 // Renders |value| as a string. |value| may be NULL, in which case the result |
48 // is an empty string. This method can be expensive and its result should be | 48 // is an empty string. This method can be expensive and its result should be |
49 // re-used rather than recomputed where possible. | 49 // re-used rather than recomputed where possible. |
50 std::string ValueAsString(const base::Value* value) { | 50 std::string ValueAsString(const base::Value* value) { |
51 // Dictionary values may contain empty lists and sub-dictionaries. Make a | 51 // Dictionary values may contain empty lists and sub-dictionaries. Make a |
52 // deep copy with those removed to make the hash more stable. | 52 // deep copy with those removed to make the hash more stable. |
53 const base::DictionaryValue* dict_value; | 53 const base::DictionaryValue* dict_value; |
54 scoped_ptr<base::DictionaryValue> canonical_dict_value; | 54 std::unique_ptr<base::DictionaryValue> canonical_dict_value; |
55 if (value && value->GetAsDictionary(&dict_value)) { | 55 if (value && value->GetAsDictionary(&dict_value)) { |
56 canonical_dict_value = dict_value->DeepCopyWithoutEmptyChildren(); | 56 canonical_dict_value = dict_value->DeepCopyWithoutEmptyChildren(); |
57 value = canonical_dict_value.get(); | 57 value = canonical_dict_value.get(); |
58 } | 58 } |
59 | 59 |
60 std::string value_as_string; | 60 std::string value_as_string; |
61 if (value) { | 61 if (value) { |
62 JSONStringValueSerializer serializer(&value_as_string); | 62 JSONStringValueSerializer serializer(&value_as_string); |
63 serializer.Serialize(*value); | 63 serializer.Serialize(*value); |
64 } | 64 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 digest_string)) { | 119 digest_string)) { |
120 return VALID; | 120 return VALID; |
121 } | 121 } |
122 if (VerifyDigestString(seed_, | 122 if (VerifyDigestString(seed_, |
123 GetMessage(legacy_device_id_, path, value_as_string), | 123 GetMessage(legacy_device_id_, path, value_as_string), |
124 digest_string)) { | 124 digest_string)) { |
125 return VALID_SECURE_LEGACY; | 125 return VALID_SECURE_LEGACY; |
126 } | 126 } |
127 return INVALID; | 127 return INVALID; |
128 } | 128 } |
OLD | NEW |