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 "services/preferences/tracked/pref_hash_calculator.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return message; | 79 return message; |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 PrefHashCalculator::PrefHashCalculator(const std::string& seed, | 84 PrefHashCalculator::PrefHashCalculator(const std::string& seed, |
85 const std::string& device_id, | 85 const std::string& device_id, |
86 const std::string& legacy_device_id) | 86 const std::string& legacy_device_id) |
87 : seed_(seed), device_id_(device_id), legacy_device_id_(legacy_device_id) {} | 87 : seed_(seed), device_id_(device_id), legacy_device_id_(legacy_device_id) {} |
88 | 88 |
89 PrefHashCalculator::~PrefHashCalculator() { | 89 PrefHashCalculator::~PrefHashCalculator() {} |
90 } | |
91 | 90 |
92 std::string PrefHashCalculator::Calculate(const std::string& path, | 91 std::string PrefHashCalculator::Calculate(const std::string& path, |
93 const base::Value* value) const { | 92 const base::Value* value) const { |
94 return GetDigestString(seed_, | 93 return GetDigestString(seed_, |
95 GetMessage(device_id_, path, ValueAsString(value))); | 94 GetMessage(device_id_, path, ValueAsString(value))); |
96 } | 95 } |
97 | 96 |
98 PrefHashCalculator::ValidationResult PrefHashCalculator::Validate( | 97 PrefHashCalculator::ValidationResult PrefHashCalculator::Validate( |
99 const std::string& path, | 98 const std::string& path, |
100 const base::Value* value, | 99 const base::Value* value, |
101 const std::string& digest_string) const { | 100 const std::string& digest_string) const { |
102 const std::string value_as_string(ValueAsString(value)); | 101 const std::string value_as_string(ValueAsString(value)); |
103 if (VerifyDigestString(seed_, GetMessage(device_id_, path, value_as_string), | 102 if (VerifyDigestString(seed_, GetMessage(device_id_, path, value_as_string), |
104 digest_string)) { | 103 digest_string)) { |
105 return VALID; | 104 return VALID; |
106 } | 105 } |
107 if (VerifyDigestString(seed_, | 106 if (VerifyDigestString(seed_, |
108 GetMessage(legacy_device_id_, path, value_as_string), | 107 GetMessage(legacy_device_id_, path, value_as_string), |
109 digest_string)) { | 108 digest_string)) { |
110 return VALID_SECURE_LEGACY; | 109 return VALID_SECURE_LEGACY; |
111 } | 110 } |
112 return INVALID; | 111 return INVALID; |
113 } | 112 } |
OLD | NEW |