UnlockReferralItem.cpp [plain text]
#include <security_keychain/UnlockReferralItem.h>
#include <security_cdsa_utilities/Schema.h>
#include <security_keychain/SecCFTypes.h>
namespace Security {
namespace KeychainCore {
UnlockReferralItem::UnlockReferralItem() :
ItemImpl((SecItemClass) CSSM_DL_DB_RECORD_UNLOCK_REFERRAL,
reinterpret_cast<SecKeychainAttributeList *>(NULL),
UInt32(0),
NULL)
{
secinfo("referral", "create %p", this);
}
UnlockReferralItem::~UnlockReferralItem()
{
secinfo("referral", "destroy %p", this);
}
PrimaryKey UnlockReferralItem::add(Keychain &keychain)
{
StLock<Mutex>_(mMutex);
if (mKeychain)
MacOSError::throwMe(errSecDuplicateItem);
populateAttributes();
CSSM_DB_RECORDTYPE recordType = mDbAttributes->recordType();
Db db(keychain->database());
try
{
mUniqueId = db->insert(recordType, mDbAttributes.get(), mData.get());
secinfo("usertrust", "%p inserted", this);
}
catch (const CssmError &e)
{
if (e.osStatus() != CSSMERR_DL_INVALID_RECORDTYPE)
throw;
secinfo("usertrust", "adding schema relation for user trusts");
#if 0
db->createRelation(CSSM_DL_DB_RECORD_UNLOCK_REFERRAL,
"CSSM_DL_DB_RECORD_UNLOCK_REFERRAL",
Schema::UnlockReferralSchemaAttributeCount,
Schema::UnlockReferralSchemaAttributeList,
Schema::UnlockReferralSchemaIndexCount,
Schema::UnlockReferralSchemaIndexList);
keychain->keychainSchema()->didCreateRelation(
CSSM_DL_DB_RECORD_UNLOCK_REFERRAL,
"CSSM_DL_DB_RECORD_UNLOCK_REFERRAL",
Schema::UnlockReferralSchemaAttributeCount,
Schema::UnlockReferralSchemaAttributeList,
Schema::UnlockReferralSchemaIndexCount,
Schema::UnlockReferralSchemaIndexList);
#endif
mUniqueId = db->insert(recordType, mDbAttributes.get(), mData.get());
secinfo("usertrust", "%p inserted now", this);
}
mPrimaryKey = keychain->makePrimaryKey(recordType, mUniqueId);
mKeychain = keychain;
return mPrimaryKey;
}
void UnlockReferralItem::populateAttributes()
{
#if 0
CssmAutoData encodedIndex(Allocator::standard());
makeCertIndex(mCertificate, encodedIndex);
const CssmOid &policyOid = mPolicy->oid();
mDbAttributes->add(Schema::attributeInfo(kSecTrustCertAttr), encodedIndex.get());
mDbAttributes->add(Schema::attributeInfo(kSecTrustPolicyAttr), policyOid);
#endif
}
} }