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

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

Issue 6873156: Move crypto_helpers from sync to base (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Follow bbretw review Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « base/rand_util_unittest.cc ('k') | chrome/browser/sync/engine/syncapi.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/keychain_mac.h" 9 #include "chrome/browser/keychain_mac.h"
10 #include "chrome/browser/sync/util/crypto_helpers.h" 10 #include "chrome/common/random.h"
11 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Generates a random password and adds it to the Keychain. The added password 15 // Generates a random password and adds it to the Keychain. The added password
16 // is returned from the function. If an error occurs, an empty password is 16 // is returned from the function. If an error occurs, an empty password is
17 // returned. 17 // returned.
18 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain, 18 std::string AddRandomPasswordToKeychain(const MacKeychain& keychain,
19 const std::string& service_name, 19 const std::string& service_name,
20 const std::string& account_name) { 20 const std::string& account_name) {
21 std::string password = Generate128BitRandomHexString(); 21 std::string password = Generate128BitRandomBase64String();
22 void* password_data = 22 void* password_data =
23 const_cast<void*>(static_cast<const void*>(password.data())); 23 const_cast<void*>(static_cast<const void*>(password.data()));
24 24
25 OSStatus error = keychain.AddGenericPassword(NULL, 25 OSStatus error = keychain.AddGenericPassword(NULL,
26 service_name.size(), 26 service_name.size(),
27 service_name.data(), 27 service_name.data(),
28 account_name.size(), 28 account_name.size(),
29 account_name.data(), 29 account_name.data(),
30 password.size(), 30 password.size(),
31 password_data, 31 password_data,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return password; 66 return password;
67 } else if (error == errSecItemNotFound) { 67 } else if (error == errSecItemNotFound) {
68 return AddRandomPasswordToKeychain(keychain_, service_name, account_name); 68 return AddRandomPasswordToKeychain(keychain_, service_name, account_name);
69 } else { 69 } else {
70 DLOG(ERROR) << "Keychain lookup failed with error " << error; 70 DLOG(ERROR) << "Keychain lookup failed with error " << error;
71 return std::string(); 71 return std::string();
72 } 72 }
73 } 73 }
74 74
75 75
OLDNEW
« no previous file with comments | « base/rand_util_unittest.cc ('k') | chrome/browser/sync/engine/syncapi.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698