| Index: chrome/browser/prefs/pref_hash_calculator.cc
|
| diff --git a/chrome/browser/prefs/pref_hash_calculator.cc b/chrome/browser/prefs/pref_hash_calculator.cc
|
| index 4a787a8a1abb699d8a3447c3a34caf3eee638bb8..24d771a31c45dfd65bb2850b4aa2a5415574b1f7 100644
|
| --- a/chrome/browser/prefs/pref_hash_calculator.cc
|
| +++ b/chrome/browser/prefs/pref_hash_calculator.cc
|
| @@ -16,6 +16,17 @@
|
|
|
| namespace {
|
|
|
| +// Calculates an HMAC of |message| using |key|, encoded as a hexadecimal string.
|
| +std::string GetHMACHex(const std::string& key, const std::string& message) {
|
| + crypto::HMAC hmac(crypto::HMAC::SHA256);
|
| + std::vector<uint8> digest(hmac.DigestLength());
|
| + if (!hmac.Init(key) || !hmac.Sign(message, &digest[0], digest.size())) {
|
| + NOTREACHED();
|
| + return std::string();
|
| + }
|
| + return base::HexEncode(digest.data(), digest.size());
|
| +}
|
| +
|
| // Renders |value| as a string. |value| may be NULL, in which case the result
|
| // is an empty string.
|
| std::string ValueAsString(const base::Value* value) {
|
| @@ -42,25 +53,28 @@ std::string CalculateFromValueAndComponents(
|
| const std::string& seed,
|
| const base::Value* value,
|
| const std::vector<std::string>& extra_components) {
|
| - static const size_t kSHA256DigestSize = 32;
|
| -
|
| std::string message = JoinString(extra_components, "") + ValueAsString(value);
|
| + return GetHMACHex(seed, message);
|
| +}
|
|
|
| - crypto::HMAC hmac(crypto::HMAC::SHA256);
|
| - unsigned char digest[kSHA256DigestSize];
|
| - if (!hmac.Init(seed) || !hmac.Sign(message, digest, arraysize(digest))) {
|
| - NOTREACHED();
|
| - return std::string();
|
| - }
|
|
|
| - return base::HexEncode(digest, arraysize(digest));
|
| +// Generates a device ID based on the input device ID. The derived device ID has
|
| +// no useful properties beyond those of the input device ID except that it is
|
| +// consistent with previous implementations.
|
| +std::string GenerateDeviceIdLikePrefMetricsServiceDid(
|
| + const std::string& original_device_id) {
|
| + if (original_device_id.empty())
|
| + return std::string();
|
| + return StringToLowerASCII(
|
| + GetHMACHex(original_device_id, "PrefMetricsService"));
|
| }
|
|
|
| } // namespace
|
|
|
| PrefHashCalculator::PrefHashCalculator(const std::string& seed,
|
| const std::string& device_id)
|
| - : seed_(seed), device_id_(device_id) {}
|
| + : seed_(seed),
|
| + device_id_(GenerateDeviceIdLikePrefMetricsServiceDid(device_id)) {}
|
|
|
| std::string PrefHashCalculator::Calculate(const std::string& path,
|
| const base::Value* value) const {
|
|
|