]> git.saurik.com Git - apple/security.git/blob - Keychain/SecCFTypes.cpp
a6a0e378fe816a0d3f06d983a88007777436d3e4
[apple/security.git] / Keychain / SecCFTypes.cpp
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.cpp - CF runtime interface
20 //
21
22 #include <Security/SecCFTypes.h>
23 #include <Security/SecRuntime.h>
24 #include <Security/threading.h>
25 #include <Security/Globals.h>
26
27 namespace Security
28 {
29
30 namespace KeychainCore
31 {
32
33 SecCFTypes &
34 gTypes()
35 {
36 static ModuleNexus<SecCFTypes> nexus;
37
38 return nexus();
39 }
40
41 } // end namespace KeychainCore
42
43 } // end namespace Security
44
45 using namespace KeychainCore;
46
47 SecCFTypes::SecCFTypes() :
48 Access("SecAccess"),
49 ACL("SecACL"),
50 Certificate("SecCertificate"),
51 CertificateRequest("SecCertificateRequest"),
52 Identity("SecIdentity"),
53 IdentityCursor("SecIdentitySearch"),
54 ItemImpl("SecKeychainItem"),
55 KCCursorImpl("SecKeychainSearch"),
56 KeychainImpl("SecKeychain"),
57 KeyItem("SecKey"),
58 Policy("SecPolicy"),
59 PolicyCursor("SecPolicySearch"),
60 Trust("SecTrust"),
61 TrustedApplication("SecTrustedApplication")
62 {
63 }
64
65 //
66 // CFClass
67 //
68 CFClass::CFClass(const char *name)
69 {
70 // initialize the CFRuntimeClass structure
71 version = 0;
72 className = name;
73 init = NULL;
74 copy = NULL;
75 finalize = finalizeType;
76 equal = equalType;
77 hash = hashType;
78 copyFormattingDesc = copyFormattingDescType;
79 copyDebugDesc = copyDebugDescType;
80
81 // register
82 typeID = _CFRuntimeRegisterClass(this);
83 assert(typeID != _kCFRuntimeNotATypeID);
84 }
85
86 void
87 CFClass::finalizeType(CFTypeRef cf)
88 {
89 /*
90 * Called on a CFRelease of any Sec object: single thread through
91 * same lock held by public API calls. This is a recursive lock
92 * so it's safe to do this for CF objects allocated and released
93 * within the Sec layer.
94 */
95 StLock<Mutex> _(globals().apiLock);
96 SecCFObject *obj = SecCFObject::optional(cf);
97 if (!obj->isNew())
98 obj->~SecCFObject();
99 }
100
101 Boolean
102 CFClass::equalType(CFTypeRef cf1, CFTypeRef cf2)
103 {
104 // CF checks for pointer equality and ensures type equality already
105 return SecCFObject::optional(cf1)->equal(*SecCFObject::optional(cf2));
106 }
107
108 CFHashCode
109 CFClass::hashType(CFTypeRef cf)
110 {
111 return SecCFObject::optional(cf)->hash();
112 }
113
114 CFStringRef
115 CFClass::copyFormattingDescType(CFTypeRef cf, CFDictionaryRef dict)
116 {
117 return SecCFObject::optional(cf)->copyFormattingDesc(dict);
118 }
119
120 CFStringRef
121 CFClass::copyDebugDescType(CFTypeRef cf)
122 {
123 return SecCFObject::optional(cf)->copyDebugDesc();
124 }