Support for process-wide incidents in the safe browsing incident reporting service.
[chromium-blink-merge.git] / crypto / apple_keychain.h
blob840ccee8c2032cc4b3914443d6c1f381eccd703f
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 #ifndef CRYPTO_KEYCHAIN_MAC_H_
6 #define CRYPTO_KEYCHAIN_MAC_H_
8 #include <Security/Security.h>
10 #include "base/basictypes.h"
11 #include "crypto/crypto_export.h"
13 #if defined (OS_IOS)
14 typedef void* SecKeychainRef;
15 typedef void* SecKeychainItemRef;
16 typedef void SecKeychainAttributeList;
17 #endif
19 namespace crypto {
21 // Wraps the KeychainServices API in a very thin layer, to allow it to be
22 // mocked out for testing.
24 // See Keychain Services documentation for function documentation, as these call
25 // through directly to their Keychain Services equivalents (Foo ->
26 // SecKeychainFoo). The only exception is Free, which should be used for
27 // anything returned from this class that would normally be freed with
28 // CFRelease (to aid in testing).
29 class CRYPTO_EXPORT AppleKeychain {
30 public:
31 AppleKeychain();
32 virtual ~AppleKeychain();
34 virtual OSStatus FindGenericPassword(CFTypeRef keychainOrArray,
35 UInt32 serviceNameLength,
36 const char* serviceName,
37 UInt32 accountNameLength,
38 const char* accountName,
39 UInt32* passwordLength,
40 void** passwordData,
41 SecKeychainItemRef* itemRef) const;
43 virtual OSStatus ItemFreeContent(SecKeychainAttributeList* attrList,
44 void* data) const;
46 virtual OSStatus AddGenericPassword(SecKeychainRef keychain,
47 UInt32 serviceNameLength,
48 const char* serviceName,
49 UInt32 accountNameLength,
50 const char* accountName,
51 UInt32 passwordLength,
52 const void* passwordData,
53 SecKeychainItemRef* itemRef) const;
55 #if !defined(OS_IOS)
56 virtual OSStatus ItemCopyAttributesAndData(
57 SecKeychainItemRef itemRef,
58 SecKeychainAttributeInfo* info,
59 SecItemClass* itemClass,
60 SecKeychainAttributeList** attrList,
61 UInt32* length,
62 void** outData) const;
64 virtual OSStatus ItemModifyAttributesAndData(
65 SecKeychainItemRef itemRef,
66 const SecKeychainAttributeList* attrList,
67 UInt32 length,
68 const void* data) const;
70 virtual OSStatus ItemFreeAttributesAndData(SecKeychainAttributeList* attrList,
71 void* data) const;
73 virtual OSStatus ItemDelete(SecKeychainItemRef itemRef) const;
75 virtual OSStatus SearchCreateFromAttributes(
76 CFTypeRef keychainOrArray,
77 SecItemClass itemClass,
78 const SecKeychainAttributeList* attrList,
79 SecKeychainSearchRef* searchRef) const;
81 virtual OSStatus SearchCopyNext(SecKeychainSearchRef searchRef,
82 SecKeychainItemRef* itemRef) const;
84 virtual OSStatus AddInternetPassword(SecKeychainRef keychain,
85 UInt32 serverNameLength,
86 const char* serverName,
87 UInt32 securityDomainLength,
88 const char* securityDomain,
89 UInt32 accountNameLength,
90 const char* accountName,
91 UInt32 pathLength, const char* path,
92 UInt16 port, SecProtocolType protocol,
93 SecAuthenticationType authenticationType,
94 UInt32 passwordLength,
95 const void* passwordData,
96 SecKeychainItemRef* itemRef) const;
98 // Calls CFRelease on the given ref, after checking that |ref| is non-NULL.
99 virtual void Free(CFTypeRef ref) const;
100 #endif // !defined(OS_IOS)
102 private:
103 DISALLOW_COPY_AND_ASSIGN(AppleKeychain);
106 } // namespace crypto
108 #endif // CRYPTO_KEYCHAIN_MAC_H_