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 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class Value; | 13 class Value; |
14 } // namespace base | 14 } // namespace base |
15 | 15 |
16 // Calculates and validates preference value hashes. | 16 // Calculates and validates preference value hashes. |
17 class PrefHashCalculator { | 17 class PrefHashCalculator { |
18 public: | 18 public: |
19 enum ValidationResult { | 19 enum ValidationResult { |
20 INVALID, | 20 INVALID, |
21 VALID, | 21 VALID, |
22 VALID_LEGACY, | 22 VALID_LEGACY, |
23 }; | 23 }; |
24 | 24 |
25 // Constructs a PrefHashCalculator using |seed| and |device_id|. The same | 25 // Constructs a PrefHashCalculator using |seed| and |device_id|. The same |
26 // parameters must be used in order to successfully validate generated hashes. | 26 // parameters must be used in order to successfully validate generated hashes. |
27 // |device_id| may be empty. | 27 // |device_id| may be empty. |
28 PrefHashCalculator(const std::string& seed, const std::string& device_id); | 28 PrefHashCalculator(const std::string& seed, const std::string& device_id); |
Ryan Sleevi
2014/01/09 22:35:16
naming nit: |seed| is usually used as the base for
gab
2014/01/09 23:03:45
Yea, that had been bugging me too, but the term "h
| |
29 | 29 |
30 // Calculates a hash value for the supplied preference |path| and |value|. | 30 // Calculates a hash value for the supplied preference |path| and |value|. |
31 // |value| may be null if the preference has no value. | 31 // |value| may be null if the preference has no value. |
32 std::string Calculate(const std::string& path, const base::Value* value) | 32 std::string Calculate(const std::string& path, const base::Value* value) |
33 const; | 33 const; |
34 | 34 |
35 // Validates the provided preference hash using current and legacy hashing | 35 // Validates the provided preference hash using current and legacy hashing |
36 // algorithms. | 36 // algorithms. |
37 ValidationResult Validate(const std::string& path, | 37 ValidationResult Validate(const std::string& path, |
38 const base::Value* value, | 38 const base::Value* value, |
39 const std::string& hash) const; | 39 const std::string& hash) const; |
40 | 40 |
41 private: | 41 private: |
42 // Calculate a hash using a deprecated hash algorithm. For validating old | 42 std::string GetMessage(const std::string& path, |
43 // hashes during migration. | 43 const base::Value* value) const; |
44 std::string CalculateLegacyHash(const std::string& path, | |
45 const base::Value* value) const; | |
46 | 44 |
47 std::string seed_; | 45 std::string seed_; |
48 std::string device_id_; | 46 std::string device_id_; |
49 | 47 |
50 DISALLOW_COPY_AND_ASSIGN(PrefHashCalculator); | 48 DISALLOW_COPY_AND_ASSIGN(PrefHashCalculator); |
51 }; | 49 }; |
52 | 50 |
53 #endif // CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ | 51 #endif // CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
OLD | NEW |