Refactors GetDeviceIdentifier()
This refactors GetDeviceIdentifier function into GetDeviceIdentifier
and GetSaltedString. GetSaltedString is a utility function that can
be used elsewhere.
Review URL: https://codereview.chromium.org/309963003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274520 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/ios/device_util.mm b/base/ios/device_util.mm
index 1edcfb6c..8449537 100644
--- a/base/ios/device_util.mm
+++ b/base/ios/device_util.mm
@@ -157,8 +157,16 @@
[defaults synchronize];
}
- NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id,
- salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding];
+ return GetSaltedString([client_id UTF8String], salt ? salt : kDefaultSalt);
+}
+
+std::string GetSaltedString(const std::string& in_string,
+ const std::string& salt) {
+ DCHECK(in_string.length());
+ DCHECK(salt.length());
+ NSData* hash_data =
+ [[NSString stringWithFormat:@"%s%s", in_string.c_str(), salt.c_str()]
+ dataUsingEncoding:NSUTF8StringEncoding];
unsigned char hash[CC_SHA256_DIGEST_LENGTH];
CC_SHA256([hash_data bytes], [hash_data length], hash);