| 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 COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_CALCULATOR_H_ | |
| 6 #define COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_CALCULATOR_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class Value; | |
| 14 } // namespace base | |
| 15 | |
| 16 // Calculates and validates preference value hashes. | |
| 17 class PrefHashCalculator { | |
| 18 public: | |
| 19 enum ValidationResult { | |
| 20 INVALID, | |
| 21 VALID, | |
| 22 // Valid under a deprecated but as secure algorithm. | |
| 23 VALID_SECURE_LEGACY, | |
| 24 }; | |
| 25 | |
| 26 // Constructs a PrefHashCalculator using |seed|, |device_id| and | |
| 27 // |legacy_device_id|. The same parameters must be used in order to | |
| 28 // successfully validate generated hashes. |_device_id| or |legacy_device_id| | |
| 29 // may be empty. | |
| 30 PrefHashCalculator(const std::string& seed, | |
| 31 const std::string& device_id, | |
| 32 const std::string& legacy_device_id); | |
| 33 | |
| 34 ~PrefHashCalculator(); | |
| 35 | |
| 36 // Calculates a hash value for the supplied preference |path| and |value|. | |
| 37 // |value| may be null if the preference has no value. | |
| 38 std::string Calculate(const std::string& path, | |
| 39 const base::Value* value) const; | |
| 40 | |
| 41 // Validates the provided preference hash using current and legacy hashing | |
| 42 // algorithms. | |
| 43 ValidationResult Validate(const std::string& path, | |
| 44 const base::Value* value, | |
| 45 const std::string& hash) const; | |
| 46 | |
| 47 private: | |
| 48 const std::string seed_; | |
| 49 const std::string device_id_; | |
| 50 const std::string legacy_device_id_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(PrefHashCalculator); | |
| 53 }; | |
| 54 | |
| 55 #endif // COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_CALCULATOR_H_ | |
| OLD | NEW |