Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / user_prefs / tracked / pref_hash_calculator.h
blob593828ec213a68683ace1d9e11581be9bfcbbba6
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 COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_CALCULATOR_H_
6 #define COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_CALCULATOR_H_
8 #include <string>
10 #include "base/basictypes.h"
12 namespace base {
13 class Value;
14 } // namespace base
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,
26 // Constructs a PrefHashCalculator using |seed| and |device_id|. The same
27 // parameters must be used in order to successfully validate generated hashes.
28 // |device_id| may be empty.
29 PrefHashCalculator(const std::string& seed, const std::string& device_id);
31 ~PrefHashCalculator();
33 // Calculates a hash value for the supplied preference |path| and |value|.
34 // |value| may be null if the preference has no value.
35 std::string Calculate(const std::string& path,
36 const base::Value* value) const;
38 // Validates the provided preference hash using current and legacy hashing
39 // algorithms.
40 ValidationResult Validate(const std::string& path,
41 const base::Value* value,
42 const std::string& hash) const;
44 private:
45 const std::string seed_;
46 const std::string device_id_;
47 const std::string legacy_device_id_;
49 DISALLOW_COPY_AND_ASSIGN(PrefHashCalculator);
52 #endif // COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_CALCULATOR_H_