Db
MultiDLDbImpl::database(const DLDbIdentifier &dlDbIdentifier)
{
	StLock<Mutex> _(mLock);
	DbMap::const_iterator it = mDbMap.find(dlDbIdentifier);
	if (it != mDbMap.end())
		return it->second;

	Module module(dlDbIdentifier.ssuid().guid(), cssm());
	DL dl;
	if (dlDbIdentifier.ssuid().subserviceType() & CSSM_SERVICE_CSP)
	{
		if (mUseSecureStorage)
			dl = SSCSPDL(module);
		else
			dl = CSPDL(module);
	}
	else
		dl = DL(module);

	dl->subserviceId(dlDbIdentifier.ssuid().subserviceId());
	dl->version(dlDbIdentifier.ssuid().version());
	Db db(dl, dlDbIdentifier.dbName());
	if (find(mListRef->begin(), mListRef->end(), dlDbIdentifier) != mListRef->end())
		mDbMap.insert(DbMap::value_type(dlDbIdentifier, db));

	return db;
}
Item ItemImpl::makeFromPersistentReference(const CFDataRef persistentRef, bool *isIdentityRef)
{
	CssmData dictData((void*)::CFDataGetBytePtr(persistentRef), ::CFDataGetLength(persistentRef));
	NameValueDictionary dict(dictData);

	Keychain keychain;
	Item item = (ItemImpl *) NULL;

	if (isIdentityRef) {
		*isIdentityRef = (dict.FindByName(IDENTITY_KEY) != 0) ? true : false;
	}

	// make sure we have a database identifier
	if (dict.FindByName(SSUID_KEY) != 0)
	{
		DLDbIdentifier dlDbIdentifier = NameValueDictionary::MakeDLDbIdentifierFromNameValueDictionary(dict);
		DLDbIdentifier newDlDbIdentifier(dlDbIdentifier.ssuid(),
				DLDbListCFPref::ExpandTildesInPath(dlDbIdentifier.dbName()).c_str(),
				dlDbIdentifier.dbLocation());

		keychain = globals().storageManager.keychain(newDlDbIdentifier);

		const NameValuePair* aDictItem = dict.FindByName(ITEM_KEY);
		if (aDictItem && keychain)
		{
			PrimaryKey primaryKey(aDictItem->Value());
			item = keychain->item(primaryKey);
		}
	}
	KCThrowIf_( !item, errSecItemNotFound );
	return item;
}