pref_hash_calculator.h 1.8 KB

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