]>
git.saurik.com Git - apple/security.git/blob - Keychain/SecRuntime.cpp
ec87f19fd744b78b6bec77a37f33afc09526a40a
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.cpp - CF runtime interface
22 #include <Security/SecRuntime.h>
23 #include <Security/SecCFTypes.h>
25 using namespace KeychainCore
;
30 SecCFObject::~SecCFObject()
35 SecCFObject::equal(SecCFObject
&other
)
37 return this == &other
;
43 return CFHashCode(this);
50 SecCFType::SecCFType(SecCFObject
*obj
) :
55 SecCFType::~SecCFType()
63 CFClassBase::CFClassBase(const char *name
)
65 // initialize the CFRuntimeClass structure
70 finalize
= finalizeType
;
73 copyFormattingDesc
= NULL
;
77 typeId
= _CFRuntimeRegisterClass(this);
78 assert(typeId
!= _kCFRuntimeNotATypeID
);
82 CFClassBase::finalizeType(CFTypeRef cf
)
84 const SecCFType
*type
= reinterpret_cast<const SecCFType
*>(cf
);
85 StLock
<Mutex
> _(gTypes().mapLock
);
86 gTypes().map
.erase(type
->mObject
.get());
91 CFClassBase::equalType(CFTypeRef cf1
, CFTypeRef cf2
)
93 const SecCFType
*t1
= reinterpret_cast<const SecCFType
*>(cf1
);
94 const SecCFType
*t2
= reinterpret_cast<const SecCFType
*>(cf2
);
95 // CF checks for pointer equality and ensures type equality already
96 return t1
->mObject
->equal(*t2
->mObject
);
100 CFClassBase::hashType(CFTypeRef cf
)
102 return reinterpret_cast<const SecCFType
*>(cf
)->mObject
->hash();
106 CFClassBase::makeNew(SecCFObject
*obj
)
108 void *p
= const_cast<void *>(_CFRuntimeCreateInstance(NULL
, typeId
,
109 sizeof(SecCFType
) - sizeof(CFRuntimeBase
), NULL
));
110 new (p
) SecCFType(obj
);
111 return reinterpret_cast<const SecCFType
*>(p
);
115 CFClassBase::handle(SecCFObject
*obj
)
117 SecCFTypes::Map
&map
= gTypes().map
;
118 StLock
<Mutex
> _(gTypes().mapLock
);
119 SecCFTypes::Map::const_iterator it
= map
.find(obj
);
122 const SecCFType
*p
= makeNew(obj
);
128 CFRetain(it
->second
);
134 CFClassBase::required(const SecCFType
*type
, OSStatus errorCode
)
137 MacOSError::throwMe(errorCode
);
139 return type
->mObject
.get();