#include <Security/KeyItem.h>
#include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
using namespace KeychainCore;
KeyItem::KeyItem(const Keychain &keychain, const PrimaryKey &primaryKey, const CssmClient::DbUniqueRecord &uniqueId) :
ItemImpl(keychain, primaryKey, uniqueId),
mKey(NULL)
{
}
KeyItem::KeyItem(const Keychain &keychain, const PrimaryKey &primaryKey) :
ItemImpl(keychain, primaryKey),
mKey(NULL)
{
}
KeyItem::KeyItem(KeyItem &keyItem) :
ItemImpl(keyItem),
mKey(NULL)
{
}
KeyItem::~KeyItem()
{
if (mKey)
{
CssmClient::SSDbUniqueRecord uniqueId(ssDbUniqueRecord());
uniqueId->database()->csp()->freeKey(*mKey);
uniqueId->allocator().free(mKey);
}
}
void
KeyItem::update()
{
MacOSError::throwMe(unimpErr);
}
Item
KeyItem::copyTo(const Keychain &keychain)
{
MacOSError::throwMe(unimpErr);
}
void
KeyItem::didModify()
{
}
PrimaryKey
KeyItem::add(Keychain &keychain)
{
MacOSError::throwMe(unimpErr);
}
CssmClient::SSDbUniqueRecord
KeyItem::ssDbUniqueRecord()
{
DbUniqueRecordImpl *impl = &*dbUniqueRecord();
return CssmClient::SSDbUniqueRecord(safe_cast<Security::CssmClient::SSDbUniqueRecordImpl *>(impl));
}
const CssmKey &
KeyItem::cssmKey()
{
if (!mKey)
{
CssmClient::SSDbUniqueRecord uniqueId(ssDbUniqueRecord());
CssmDataContainer dataBlob(uniqueId->allocator());
uniqueId->get(NULL, &dataBlob);
mKey = reinterpret_cast<CssmKey *>(dataBlob.Data);
dataBlob.Data = NULL;
dataBlob.Length = 0;
}
return *mKey;
}