2 * Copyright (c) 2002-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 // SecCFTypes.h - CF runtime interface
27 #ifndef _SECURITY_SECCFTYPES_H_
28 #define _SECURITY_SECCFTYPES_H_
30 #include <CoreFoundation/CFRuntime.h>
31 #include <security_utilities/globalizer.h>
32 #include <security_utilities/cfclass.h>
37 namespace KeychainCore
40 /* Singleton that registers all the CFClass instances with the CFRuntime.
42 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.
44 In addition to that you need to define an opque type for the C API like:
45 typedef struct __OpaqueYourObject *YourObjectRef;
47 Add an instance of CFClass to the public section of SecCFTypes below to get it registered with the CFRuntime.
51 In your C++ code you should use SecPointer<YourObject> to refer to instances of your class. SecPointers 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:
53 SecPointer<YourObject> instance(new YourObject());
55 SecPointers have copy semantics and if you subclass SecPointer and define a operator < on the subclass you can even safely store instances of your class in stl containers.
58 instance->somemethod();
59 or if you want a reference to the underlying object:
60 YourObject &object = *instance;
61 if you want a pointer to the underlying object:
62 YourObject *object = instance.get();
64 In the API glue you will need to use:
65 SecPointer<YourObject> instance;
66 [...] get the instance somehow
67 return instance->handle();
68 to return an opaque handle (the is a CFTypeRef) to your object.
70 when you obtain an object as input use:
72 SecPointer<YourObject> instance = YourObject::required(ref);
73 to get a SecPointer to an instance of your object from the external CFTypeRef.
81 /* Add new instances of CFClass here that you want registered with the CF runtime. */
85 CFClass CertificateRequest
;
87 CFClass IdentityCursor
;
96 CFClass TrustedApplication
;
97 CFClass ExtendedAttribute
;
100 extern SecCFTypes
&gTypes();
102 } // end namespace KeychainCore
104 } // end namespace Security
107 #endif // !_SECURITY_SECCFTYPES_H_