]>
git.saurik.com Git - apple/security.git/blob - Keychain/DefaultKeychain.cpp
2 * Copyright (c) 2000-2001 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.
20 File: DefaultKeychain.cpp
22 Contains: User preference for default keychain
24 Copyright: 2000 by Apple Computer, Inc., all rights reserved.
29 #include "DefaultKeychain.h"
31 #include "CCallbackMgr.h"
32 #include "KCEventNotifier.h"
33 #include "Keychains.h"
35 #include "KCExceptions.h"
37 using namespace KeychainCore
;
38 using namespace CssmClient
;
40 DefaultKeychain::DefaultKeychain() : mPref(CFSTR("DefaultKeychain"))
44 // Set/Get via DLDbIdentifier
45 void DefaultKeychain::dLDbIdentifier(const DLDbIdentifier
& keychainID
)
47 DLDbList
& theList
=mPref
.list();
48 if (theList
.size()>0 && keychainID
==theList
[0]) // already the default keychain
51 mPref
.add(keychainID
); // destructor will save
53 KCEventNotifier::PostKeychainEvent(kSecDefaultChangedEvent
, keychainID
);
54 defaultID
= keychainID
;
58 void DefaultKeychain::unset()
60 DLDbList
& theList
=mPref
.list();
62 mPref
.clearDefaultKeychain();
63 KCEventNotifier::PostKeychainEvent(kSecDefaultChangedEvent
);
66 void DefaultKeychain::reload(bool force
)
68 if (!defaultID
|| mPref
.revert(force
))
70 DLDbList
& theList
=mPref
.list();
71 if (theList
.size()==0)
72 MacOSError::throwMe(errSecNoDefaultKeychain
);
73 defaultID
= theList
[0];
77 DLDbIdentifier
DefaultKeychain::dLDbIdentifier()
83 // Set/Get via Keychain
84 void DefaultKeychain::keychain(const Keychain
& keychain
)
86 DefaultKeychain::dLDbIdentifier(keychain
->dLDbIdentifier()); // call the main "set" routine
89 Keychain
DefaultKeychain::keychain() // was: GetTimedDefaultKC
91 return globals().storageManager
.keychain(dLDbIdentifier());
94 bool DefaultKeychain::isSet()
96 return mPref
.list().size() != 0;