OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
| 6 #define CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 namespace base { |
| 11 class Value; |
| 12 } // namespace base |
| 13 |
| 14 // Calculates and validates preference value hashes. |
| 15 // This class is intentionally copy-constructable. |
| 16 class PrefHashCalculator { |
| 17 public: |
| 18 enum ValidationResult { |
| 19 INVALID, |
| 20 VALID, |
| 21 VALID_LEGACY |
| 22 }; |
| 23 |
| 24 // Constructs a PrefHashCalculator using |seed| and |device_id|. The same |
| 25 // parameters must be used in order to successfully validate generated hashes. |
| 26 // |
| 27 // |device_id| may be empty. |
| 28 PrefHashCalculator(const std::string& seed, const std::string& device_id); |
| 29 |
| 30 // Calculates a hash value for the supplied preference path and value. |value| |
| 31 // may be null if the preference has no value. |
| 32 std::string Calculate(const std::string& path, const base::Value* value); |
| 33 |
| 34 // Validates the provided preference hash using current and legacy hashing |
| 35 // algorithms. |
| 36 ValidationResult Validate(const std::string& path, |
| 37 const base::Value* value, |
| 38 const std::string& hash); |
| 39 |
| 40 private: |
| 41 // Calculate a hash using a deprecated hash algorithm. For validating old |
| 42 // hashes during migration. |
| 43 std::string CalculateLegacyHash(const std::string& path, |
| 44 const base::Value* value); |
| 45 |
| 46 std::string seed_; |
| 47 std::string device_id_; |
| 48 }; |
| 49 |
| 50 #endif // CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
OLD | NEW |