OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "base/logging.h" | |
6 #include "base/time.h" | |
7 #include "crypto/mock_apple_keychain.h" | |
8 | |
9 namespace crypto { | |
10 | |
11 OSStatus MockAppleKeychain::FindGenericPassword( | |
12 CFTypeRef keychainOrArray, | |
13 UInt32 serviceNameLength, | |
14 const char* serviceName, | |
15 UInt32 accountNameLength, | |
16 const char* accountName, | |
17 UInt32* passwordLength, | |
18 void** passwordData, | |
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 char password[] = "my_password"; | |
Ryan Sleevi
2012/08/23 22:22:58
nit: static const char kPassword[] = "my_password"
msarda
2012/08/27 14:24:07
Done.
| |
24 | |
25 DCHECK(passwordData); | |
26 *passwordData = static_cast<void*>(password); | |
27 DCHECK(passwordLength); | |
28 *passwordLength = strlen(password); | |
Ryan Sleevi
2012/08/23 22:22:58
arraysize
msarda
2012/08/27 14:24:07
Done.
| |
29 password_data_count_++; | |
30 } | |
31 | |
32 return find_generic_result_; | |
33 } | |
34 | |
35 OSStatus MockAppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList, | |
36 void* data) const { | |
37 // No-op. | |
38 password_data_count_--; | |
39 return noErr; | |
40 } | |
41 | |
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; | |
52 | |
53 DCHECK(passwordLength > 0); | |
Ryan Sleevi
2012/08/23 22:22:58
DCHECK_GT
msarda
2012/08/27 14:24:07
Done.
| |
54 DCHECK(passwordData); | |
55 add_generic_password_ = | |
56 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), | |
57 passwordLength); | |
58 return noErr; | |
59 } | |
60 | |
61 } // namespace crypto | |
OLD | NEW |