]> git.saurik.com Git - apple/security.git/blob - Keychain/SecCFTypes.h
Security-54.1.tar.gz
[apple/security.git] / Keychain / SecCFTypes.h
1 /*
2 * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18 //
19 // SecCFTypes.h - CF runtime interface
20 //
21 #ifndef _SECURITY_SECCFTYPES_H_
22 #define _SECURITY_SECCFTYPES_H_
23
24 #include <Security/Access.h>
25 #include <Security/ACL.h>
26 #include <Security/Certificate.h>
27 #include <Security/CertificateRequest.h>
28 #include <Security/Identity.h>
29 #include <Security/IdentityCursor.h>
30 #include <Security/Item.h>
31 #include <Security/KCCursor.h>
32 #include <Security/Keychains.h>
33 #include <Security/KeyItem.h>
34 #include <Security/Policies.h>
35 #include <Security/PolicyCursor.h>
36 #include <Security/Trust.h>
37 #include <Security/TrustedApplication.h>
38
39 //#include <Security/SecAccess.h>
40 //#include <Security/SecCertificate.h>
41 #include <Security/SecCertificateRequest.h>
42 //#include <Security/SecIdentity.h>
43 #include <Security/SecIdentitySearch.h>
44 //#include <Security/SecKeychainItem.h>
45 #include <Security/SecKeychainSearch.h>
46 //#include <Security/SecKeychain.h>
47 //#include <Security/SecKey.h>
48 //#include <Security/SecPolicy.h>
49 //#include <Security/SecACL.h>
50 #include <Security/SecPolicySearch.h>
51 #include <Security/SecTrust.h>
52 //#include <Security/SecTrustedApplication.h>
53
54 #include <Security/utilities.h>
55 #include <map>
56
57 namespace Security
58 {
59
60 namespace KeychainCore
61 {
62
63 /* Singleton that registers all the CFClass<> instances with the CFRuntime.
64
65 To make something a CFTypeRef you need to make the actual object inheirit from SecCFObject and provide implementation of the virtual functions in that class.
66
67 In addition to that you need to define an opque type for the C API like:
68 typedef struct __OpaqueYourObject *YourObjectRef;
69 and in the C++ headers you define something like:
70 typedef CFClass<YourObject, YourObjectRef> YourObjectClass;
71
72 Add an instance of the YourObjectClass to the public section of SecCFTypes below to get it registered with the CFRuntime.
73 YourObjectClass yourObject;
74
75
76 In your C++ code you should use RefPointer<YourObject> to refer to instances of your class. RefPointers are just like autopointers and implement * and -> semantics. They refcount the underlying object. So to create an instance or your new object you would do something like:
77
78 RefPointer<YourObject> instance(new YourObject());
79
80 RefPointers have copy semantics and if you subclass RefPointer and define a operator < on the subclass you can even safely store instances of your class in stl containers.
81
82 Use then like this:
83 instance->somemethod();
84 or if you want a reference to the underlying object:
85 YourObject &object = *instance;
86 if you want a pointer to the underlying object:
87 YourObject *object = instance.get();
88
89 In the API glue you will need to use:
90 RefPointer<YourObject> instance;
91 [...] get the instance somehow
92 return gTypes().yourObject.handle(*instance);
93 to return an opaque handle (the is a CFTypeRef) to your object.
94
95 when you obtain an object as input use:
96 SecYourObjectRef ref;
97 RefPointer<YourObject> instance = gTypes().yourObject.required(ref);
98 to get a RefPointer to an instance of your object fro the external CFTypeRef.
99 */
100 class SecCFTypes
101 {
102 public:
103 SecCFTypes();
104
105 public:
106 /* Add new instances of CFClass<> here that you want registered with the CF runtime. */
107
108 /* @@@ Error should be errSecInvalidAccessRef */
109 CFClass<Access, SecAccessRef, errSecInvalidItemRef> access;
110 /* @@@ Error should be errSecInvalidTrustedApplicationRef */
111 CFClass<ACL, SecACLRef, errSecInvalidItemRef> acl;
112 /* @@@ Error should be errSecInvalidCertificateRef */
113 CFClass<Certificate, SecCertificateRef, errSecInvalidItemRef> certificate;
114 /* @@@ Error should be errSecInvalidCertificateRequestRef */
115 CFClass<CertificateRequest, SecCertificateRequestRef, errSecInvalidItemRef> certificateRequest;
116 /* @@@ Error should be errSecInvalidIdentityRef */
117 CFClass<Identity, SecIdentityRef, errSecInvalidItemRef> identity;
118 CFClass<IdentityCursor, SecIdentitySearchRef, errSecInvalidSearchRef> identityCursor;
119 CFClass<ItemImpl, SecKeychainItemRef, errSecInvalidItemRef> item;
120 CFClass<KCCursorImpl, SecKeychainSearchRef, errSecInvalidSearchRef> cursor;
121 CFClass<KeychainImpl, SecKeychainRef, errSecInvalidKeychain> keychain;
122 /* @@@ Error should be errSecInvalidKeyRef */
123 CFClass<KeyItem, SecKeyRef, errSecInvalidItemRef> keyItem;
124 /* @@@ Error should be errSecInvalidPolicyRef */
125 CFClass<Policy, SecPolicyRef, errSecInvalidItemRef> policy;
126 /* @@@ Error should be errSecInvalidPolicySearchRef */
127 CFClass<PolicyCursor, SecPolicySearchRef, errSecInvalidSearchRef> policyCursor;
128 /* @@@ Error should be errSecInvalidTrustRef */
129 CFClass<Trust, SecTrustRef, errSecInvalidItemRef> trust;
130 /* @@@ Error should be errSecInvalidTrustedApplicationRef */
131 CFClass<TrustedApplication, SecTrustedApplicationRef, errSecInvalidItemRef> trustedApplication;
132
133 public:
134 Mutex mapLock;
135 typedef std::map<SecCFObject *, const SecCFType *> Map;
136 Map map;
137 };
138
139
140 extern ModuleNexus<SecCFTypes> gTypes;
141
142 } // end namespace KeychainCore
143
144 } // end namespace Security
145
146
147 #endif // !_SECURITY_SECCFTYPES_H_