]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/lib/SecIdentitySearch.cpp
Security-57740.60.18.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / lib / SecIdentitySearch.cpp
1 /*
2 * Copyright (c) 2002-2004,2011,2014-2015 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <Security/SecIdentitySearch.h>
25 #include <Security/SecIdentitySearchPriv.h>
26 #include <Security/SecPolicyPriv.h>
27 #include <security_keychain/IdentityCursor.h>
28 #include <security_keychain/Identity.h>
29
30 #include "SecBridge.h"
31
32
33 CFTypeID
34 SecIdentitySearchGetTypeID(void)
35 {
36 BEGIN_SECAPI
37
38 return gTypes().IdentityCursor.typeID;
39
40 END_SECAPI1(_kCFRuntimeNotATypeID)
41 }
42
43
44 OSStatus
45 SecIdentitySearchCreate(
46 CFTypeRef keychainOrArray,
47 CSSM_KEYUSE keyUsage,
48 SecIdentitySearchRef *searchRef)
49 {
50 BEGIN_SECAPI
51
52 Required(searchRef);
53
54 StorageManager::KeychainList keychains;
55 globals().storageManager.optionalSearchList(keychainOrArray, keychains);
56 SecPointer<IdentityCursor> identityCursor(new IdentityCursor (keychains, keyUsage));
57 *searchRef = identityCursor->handle();
58
59 END_SECAPI
60 }
61
62 OSStatus SecIdentitySearchCreateWithAttributes(
63 CFDictionaryRef attributes,
64 SecIdentitySearchRef* searchRef)
65 {
66 BEGIN_SECAPI
67
68 //
69 // %%%TBI This function needs a new form of IdentityCursor that takes
70 // the supplied attributes as input.
71 //
72 Required(searchRef);
73 StorageManager::KeychainList keychains;
74 globals().storageManager.getSearchList(keychains);
75 SecPointer<IdentityCursor> identityCursor(new IdentityCursor (keychains, 0));
76 *searchRef = identityCursor->handle();
77
78 END_SECAPI
79 }
80
81 OSStatus SecIdentitySearchCreateWithPolicy(
82 SecPolicyRef policy,
83 CFStringRef idString,
84 CSSM_KEYUSE keyUsage,
85 CFTypeRef keychainOrArray,
86 Boolean returnOnlyValidIdentities,
87 SecIdentitySearchRef* searchRef)
88 {
89 BEGIN_SECAPI
90
91 Required(searchRef);
92
93 StorageManager::KeychainList keychains;
94 globals().storageManager.optionalSearchList(keychainOrArray, keychains);
95 CFRef<SecPolicyRef> policyRef = SecPolicyCreateItemImplInstance(policy);
96 SecPointer<IdentityCursorPolicyAndID> identityCursor(new IdentityCursorPolicyAndID (keychains, keyUsage, idString, policyRef, returnOnlyValidIdentities));
97
98 *searchRef = identityCursor->handle();
99
100 END_SECAPI
101 }
102
103 OSStatus
104 SecIdentitySearchCopyNext(
105 SecIdentitySearchRef searchRef,
106 SecIdentityRef *identityRef)
107 {
108 BEGIN_SECAPI
109
110 RequiredParam(identityRef);
111 SecPointer<Identity> identityPtr;
112 if (!IdentityCursor::required(searchRef)->next(identityPtr))
113 return errSecItemNotFound;
114
115 *identityRef = identityPtr->handle();
116
117 END_SECAPI
118 }