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

Side by Side Diff: chrome/browser/password_manager/encryptor_password_mac.mm

Issue 10875029: Rename MacKeychain to AppleKeychain (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address Avi's code review: add NStoCFCast and other nits. Created 8 years, 3 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
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 "chrome/browser/password_manager/encryptor_password_mac.h" 5 #include "chrome/browser/password_manager/encryptor_password_mac.h"
6 6
7 #import <Security/Security.h> 7 #import <Security/Security.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/mac/mac_logging.h" 10 #include "base/mac/mac_logging.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "crypto/keychain_mac.h" 12 #include "crypto/apple_keychain.h"
13 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
14 14
15 using crypto::MacKeychain; 15 using crypto::AppleKeychain;
16 16
17 namespace { 17 namespace {
18 18
19 // Generates a random password and adds it to the Keychain. The added password 19 // Generates a random password and adds it to the Keychain. The added password
20 // is returned from the function. If an error occurs, an empty password is 20 // is returned from the function. If an error occurs, an empty password is
21 // returned. 21 // returned.
22 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain, 22 std::string AddRandomPasswordToKeychain(const AppleKeychain& keychain,
23 const std::string& service_name, 23 const std::string& service_name,
24 const std::string& account_name) { 24 const std::string& account_name) {
25 // Generate a password with 128 bits of randomness. 25 // Generate a password with 128 bits of randomness.
26 const int kBytes = 128 / 8; 26 const int kBytes = 128 / 8;
27 std::string password; 27 std::string password;
28 base::Base64Encode(base::RandBytesAsString(kBytes), &password); 28 base::Base64Encode(base::RandBytesAsString(kBytes), &password);
29 void* password_data = 29 void* password_data =
30 const_cast<void*>(static_cast<const void*>(password.data())); 30 const_cast<void*>(static_cast<const void*>(password.data()));
31 31
32 OSStatus error = keychain.AddGenericPassword(NULL, 32 OSStatus error = keychain.AddGenericPassword(NULL,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 std::string(static_cast<char*>(password_data), password_length); 71 std::string(static_cast<char*>(password_data), password_length);
72 keychain_.ItemFreeContent(NULL, password_data); 72 keychain_.ItemFreeContent(NULL, password_data);
73 return password; 73 return password;
74 } else if (error == errSecItemNotFound) { 74 } else if (error == errSecItemNotFound) {
75 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); 75 return AddRandomPasswordToKeychain(keychain_, service_name, account_name);
76 } else { 76 } else {
77 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed"; 77 OSSTATUS_DLOG(ERROR, error) << "Keychain lookup failed";
78 return std::string(); 78 return std::string();
79 } 79 }
80 } 80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698