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
3 // found in the LICENSE file.
5 #include "base/logging.h"
7 #include "crypto/mock_apple_keychain.h"
11 OSStatus
MockAppleKeychain::FindGenericPassword(
12 CFTypeRef keychainOrArray
,
13 UInt32 serviceNameLength
,
14 const char* serviceName
,
15 UInt32 accountNameLength
,
16 const char* accountName
,
17 UInt32
* passwordLength
,
19 SecKeychainItemRef
* itemRef
) const {
20 // When simulating |noErr|, return canned |passwordData| and
21 // |passwordLength|. Otherwise, just return given code.
22 if (find_generic_result_
== noErr
) {
23 static const char kPassword
[] = "my_password";
25 // The function to free this data is mocked so the cast is fine.
26 *passwordData
= const_cast<char*>(kPassword
);
27 DCHECK(passwordLength
);
28 *passwordLength
= arraysize(kPassword
);
29 password_data_count_
++;
32 return find_generic_result_
;
35 OSStatus
MockAppleKeychain::ItemFreeContent(SecKeychainAttributeList
* attrList
,
38 password_data_count_
--;
42 OSStatus
MockAppleKeychain::AddGenericPassword(
43 SecKeychainRef keychain
,
44 UInt32 serviceNameLength
,
45 const char* serviceName
,
46 UInt32 accountNameLength
,
47 const char* accountName
,
48 UInt32 passwordLength
,
49 const void* passwordData
,
50 SecKeychainItemRef
* itemRef
) const {
51 called_add_generic_
= true;
53 DCHECK_GT(passwordLength
, 0U);
55 add_generic_password_
=
56 std::string(const_cast<char*>(static_cast<const char*>(passwordData
)),