DefaultKeychain.cpp [plain text]
#include "DefaultKeychain.h"
#include "CCallbackMgr.h"
#include "KCEventNotifier.h"
#include "Keychains.h"
#include "Globals.h"
#include "KCExceptions.h"
using namespace KeychainCore;
using namespace CssmClient;
DefaultKeychain::DefaultKeychain() : mPref(CFSTR("DefaultKeychain"))
{
}
void DefaultKeychain::dLDbIdentifier(const DLDbIdentifier& keychainID)
{
DLDbList& theList=mPref.list();
if (theList.size()>0 && keychainID==theList[0]) return;
theList.clear();
mPref.add(keychainID); mPref.save();
KCEventNotifier::PostKeychainEvent(kSecDefaultChangedEvent, keychainID);
defaultID = keychainID;
}
void DefaultKeychain::unset()
{
DLDbList& theList=mPref.list();
theList.clear();
mPref.clearDefaultKeychain();
KCEventNotifier::PostKeychainEvent(kSecDefaultChangedEvent);
}
void DefaultKeychain::reload(bool force)
{
if (!defaultID || mPref.revert(force))
{
DLDbList& theList=mPref.list();
if (theList.size()==0)
MacOSError::throwMe(errSecNoDefaultKeychain);
defaultID = theList[0];
}
}
DLDbIdentifier DefaultKeychain::dLDbIdentifier()
{
reload();
return defaultID;
}
void DefaultKeychain::keychain(const Keychain& keychain)
{
DefaultKeychain::dLDbIdentifier(keychain->dLDbIdentifier()); }
Keychain DefaultKeychain::keychain() {
return globals().storageManager.keychain(dLDbIdentifier());
}
bool DefaultKeychain::isSet()
{
return mPref.list().size() != 0;
}