Chromium Code Reviews| Index: chrome/browser/prefs/pref_hash_calculator.h |
| diff --git a/chrome/browser/prefs/pref_hash_calculator.h b/chrome/browser/prefs/pref_hash_calculator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c9c430b5e1afb00579804a5e9beb343371ef6229 |
| --- /dev/null |
| +++ b/chrome/browser/prefs/pref_hash_calculator.h |
| @@ -0,0 +1,50 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
| +#define CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |
| + |
| +#include <string> |
| + |
| +namespace base { |
| +class Value; |
| +} // namespace base |
| + |
| +// Calculates and validates preference value hashes. |
| +// This class is intentionally copy-constructable. |
|
gab
2013/12/06 17:23:38
The only reason for this I believe is because it's
erikwright (departed)
2013/12/09 17:59:40
Done.
|
| +class PrefHashCalculator { |
| + public: |
| + enum ValidationResult { |
| + INVALID, |
| + VALID, |
| + VALID_LEGACY |
|
gab
2013/12/06 17:23:38
nit: add trailing comma
erikwright (departed)
2013/12/09 17:59:40
Done.
|
| + }; |
| + |
| + // Constructs a PrefHashCalculator using |seed| and |device_id|. The same |
| + // parameters must be used in order to successfully validate generated hashes. |
| + // |
|
gab
2013/12/06 17:23:38
nit: I don't think an empty line is required here.
erikwright (departed)
2013/12/09 17:59:40
Done.
|
| + // |device_id| may be empty. |
| + PrefHashCalculator(const std::string& seed, const std::string& device_id); |
| + |
| + // Calculates a hash value for the supplied preference path and value. |value| |
|
gab
2013/12/06 17:23:38
Put path and value in ||.
erikwright (departed)
2013/12/09 17:59:40
Done.
|
| + // may be null if the preference has no value. |
| + std::string Calculate(const std::string& path, const base::Value* value); |
|
gab
2013/12/06 17:23:38
Make this method and other methods of this class c
erikwright (departed)
2013/12/09 17:59:40
Done.
|
| + |
| + // Validates the provided preference hash using current and legacy hashing |
| + // algorithms. |
| + ValidationResult Validate(const std::string& path, |
| + const base::Value* value, |
| + const std::string& hash); |
| + |
| + private: |
| + // Calculate a hash using a deprecated hash algorithm. For validating old |
| + // hashes during migration. |
| + std::string CalculateLegacyHash(const std::string& path, |
| + const base::Value* value); |
| + |
| + std::string seed_; |
| + std::string device_id_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_PREFS_PREF_HASH_CALCULATOR_H_ |