OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/music_manager_private/device_id.h" | 5 #include "chrome/browser/extensions/api/music_manager_private/device_id.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "crypto/hmac.h" | 11 #include "crypto/hmac.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 using extensions::api::DeviceId; | 15 using extensions::api::DeviceId; |
16 | 16 |
17 // Compute HMAC-SHA256(|key|, |text|) as a string. | 17 // Compute HMAC-SHA256(|key|, |text|) as a string. |
18 bool ComputeHmacSha256(const std::string& key, | 18 bool ComputeHmacSha256(const std::string& key, |
19 const std::string& text, | 19 const std::string& text, |
20 std::string* signature_return) { | 20 std::string* signature_return) { |
21 crypto::HMAC hmac(crypto::HMAC::SHA256); | 21 crypto::HMAC hmac(crypto::HMAC::SHA256); |
22 const size_t digest_length = hmac.DigestLength(); | 22 const size_t digest_length = hmac.DigestLength(); |
23 std::vector<uint8> digest(digest_length); | 23 std::vector<uint8> digest(digest_length); |
24 bool result = hmac.Init(key) && | 24 bool result = hmac.Init(key) && |
25 hmac.Sign(text, &digest[0], digest.size()); | 25 hmac.Sign(text, &digest[0], digest.size()); |
26 if (result) { | 26 if (result) { |
27 *signature_return = base::StringToLowerASCII( | 27 *signature_return = base::ToLowerASCII( |
28 base::HexEncode(digest.data(), digest.size())); | 28 base::HexEncode(digest.data(), digest.size())); |
29 } | 29 } |
30 return result; | 30 return result; |
31 } | 31 } |
32 | 32 |
33 void GetRawDeviceIdCallback(const std::string& extension_id, | 33 void GetRawDeviceIdCallback(const std::string& extension_id, |
34 const DeviceId::IdCallback& callback, | 34 const DeviceId::IdCallback& callback, |
35 const std::string& raw_device_id) { | 35 const std::string& raw_device_id) { |
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
37 | 37 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 GetRawDeviceId(base::Bind(&GetRawDeviceIdCallback, extension_id, callback)); | 185 GetRawDeviceId(base::Bind(&GetRawDeviceIdCallback, extension_id, callback)); |
186 } | 186 } |
187 | 187 |
188 // static | 188 // static |
189 bool DeviceId::IsValidMacAddress(const void* bytes, size_t size) { | 189 bool DeviceId::IsValidMacAddress(const void* bytes, size_t size) { |
190 return IsValidMacAddressImpl(bytes, size); | 190 return IsValidMacAddressImpl(bytes, size); |
191 } | 191 } |
192 | 192 |
193 } // namespace api | 193 } // namespace api |
194 } // namespace extensions | 194 } // namespace extensions |
OLD | NEW |