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.
5 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_
6 #define CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_
10 #include "base/basictypes.h"
16 // Calculates and validates preference value hashes.
17 class PrefHashCalculator {
19 enum ValidationResult {
25 // Constructs a PrefHashCalculator using |seed| and |device_id|. The same
26 // parameters must be used in order to successfully validate generated hashes.
27 // |device_id| may be empty.
28 PrefHashCalculator(const std::string& seed, const std::string& device_id);
30 // Calculates a hash value for the supplied preference |path| and |value|.
31 // |value| may be null if the preference has no value.
32 std::string Calculate(const std::string& path, const base::Value* value)
35 // Validates the provided preference hash using current and legacy hashing
37 ValidationResult Validate(const std::string& path,
38 const base::Value* value,
39 const std::string& hash) const;
42 // Concatenates |device_id_|, |path|, and |value_as_string| to give the hash
44 std::string GetMessage(const std::string& path,
45 const std::string& value_as_string) const;
48 std::string device_id_;
50 DISALLOW_COPY_AND_ASSIGN(PrefHashCalculator);
53 #endif // CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_