Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: base/ios/device_util.mm

Issue 309963003: Refactors GetDeviceIdentifier() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/ios/device_util.h ('k') | base/ios/device_util_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/ios/device_util.h" 5 #include "base/ios/device_util.h"
6 6
7 #include <CommonCrypto/CommonDigest.h> 7 #include <CommonCrypto/CommonDigest.h>
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 9
10 #include <ifaddrs.h> 10 #include <ifaddrs.h>
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey]; 151 NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey];
152 152
153 if (!client_id || ![last_seen_hardware isEqualToString:current_hardware]) { 153 if (!client_id || ![last_seen_hardware isEqualToString:current_hardware]) {
154 client_id = GenerateClientId(); 154 client_id = GenerateClientId();
155 [defaults setObject:client_id forKey:kClientIdPreferenceKey]; 155 [defaults setObject:client_id forKey:kClientIdPreferenceKey];
156 [defaults setObject:current_hardware forKey:kHardwareTypePreferenceKey]; 156 [defaults setObject:current_hardware forKey:kHardwareTypePreferenceKey];
157 [defaults synchronize]; 157 [defaults synchronize];
158 } 158 }
159 159
160 NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id, 160 return GetSaltedString([client_id UTF8String], salt ? salt : kDefaultSalt);
161 salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding]; 161 }
162
163 std::string GetSaltedString(const std::string& in_string,
164 const std::string& salt) {
165 DCHECK(in_string.length());
166 DCHECK(salt.length());
167 NSData* hash_data =
168 [[NSString stringWithFormat:@"%s%s", in_string.c_str(), salt.c_str()]
169 dataUsingEncoding:NSUTF8StringEncoding];
162 170
163 unsigned char hash[CC_SHA256_DIGEST_LENGTH]; 171 unsigned char hash[CC_SHA256_DIGEST_LENGTH];
164 CC_SHA256([hash_data bytes], [hash_data length], hash); 172 CC_SHA256([hash_data bytes], [hash_data length], hash);
165 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); 173 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash);
166 174
167 base::ScopedCFTypeRef<CFUUIDRef> uuid_object( 175 base::ScopedCFTypeRef<CFUUIDRef> uuid_object(
168 CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); 176 CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes));
169 base::ScopedCFTypeRef<CFStringRef> device_id( 177 base::ScopedCFTypeRef<CFStringRef> device_id(
170 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); 178 CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
171 return base::SysCFStringRefToUTF8(device_id); 179 return base::SysCFStringRefToUTF8(device_id);
172 } 180 }
173 181
174 } // namespace device_util 182 } // namespace device_util
175 } // namespace ios 183 } // namespace ios
OLDNEW
« no previous file with comments | « base/ios/device_util.h ('k') | base/ios/device_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698