]>
git.saurik.com Git - apple/security.git/blob - Keychain/SecRuntime.h
2 * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
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
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.
19 // SecRuntime.h - CF runtime interface
21 #ifndef _SECURITY_SECRUNTIME_H_
22 #define _SECURITY_SECRUNTIME_H_
24 #include <CoreFoundation/CFRuntime.h>
25 #include <Security/refcount.h>
31 namespace KeychainCore
34 class SecCFObject
: public RefCount
37 virtual ~SecCFObject();
38 virtual bool equal(SecCFObject
&other
);
39 virtual CFHashCode
hash();
43 class SecCFType
: public CFRuntimeBase
46 SecCFType(SecCFObject
*obj
);
49 RefPointer
<SecCFObject
> mObject
;
53 class CFClassBase
: protected CFRuntimeClass
56 CFClassBase(const char *name
);
58 const SecCFType
*makeNew(SecCFObject
*obj
);
59 const SecCFType
*handle(SecCFObject
*obj
);
60 SecCFObject
*required(const SecCFType
*type
, OSStatus errorCode
);
63 static void finalizeType(CFTypeRef cf
);
64 static Boolean
equalType(CFTypeRef cf1
, CFTypeRef cf2
);
65 static CFHashCode
hashType(CFTypeRef cf
);
72 template <class Object
, class APITypePtr
, OSStatus ErrorCode
>
73 class CFClass
: public CFClassBase
76 CFClass(const char *name
) : CFClassBase(name
) {}
78 APITypePtr
handle(Object
&obj
)
80 return APITypePtr(CFClassBase::handle(&obj
));
83 Object
*required(APITypePtr type
)
85 Object
*object
= dynamic_cast<Object
*>(CFClassBase::required
86 (reinterpret_cast<const SecCFType
*>(type
), ErrorCode
));
88 MacOSError::throwMe(ErrorCode
);
93 // CF generator functions
94 APITypePtr
operator () (Object
*obj
)
95 { return handle(*obj
); }
97 APITypePtr
operator () (const RefPointer
<Object
> &obj
)
98 { return handle(*obj
); }
100 Object
* operator () (APITypePtr ref
)
101 { return required(ref
); }
105 } // end namespace KeychainCore
107 } // end namespace Security
110 #endif // !_SECURITY_SECRUNTIME_H_