add entryExists()
This commit is contained in:
parent
653bf190f0
commit
067c3c6577
|
@ -60,6 +60,15 @@ QByteArray Keychain::readEntry( const QString& key ) {
|
|||
return pw;
|
||||
}
|
||||
|
||||
bool Keychain::entryExists( const QString& key ) {
|
||||
QString err;
|
||||
bool exists = false;
|
||||
const Error ret = d->entryExistsImpl( &exists, key, &err );
|
||||
d->error = ret;
|
||||
d->errorString = err;
|
||||
return exists;
|
||||
}
|
||||
|
||||
void Keychain::deleteEntry( const QString& key ) {
|
||||
QString err;
|
||||
const Error ret = d->deleteEntryImpl( key, &err );
|
||||
|
|
12
keychain.h
12
keychain.h
|
@ -91,7 +91,7 @@ public:
|
|||
* Reads the password for a given @p key from the keychain.
|
||||
* error() and errorString() hold the result of the read operation.
|
||||
*
|
||||
* @param key the key ot read the password for
|
||||
* @param key the key to read the password for
|
||||
*/
|
||||
QString readPassword( const QString& key );
|
||||
|
||||
|
@ -99,10 +99,18 @@ public:
|
|||
* Reads data for a given @p key from the keychain.
|
||||
* error() and errorString() hold the result of the read operation.
|
||||
*
|
||||
* @param key the key ot read the password for
|
||||
* @param key the key to read the password for
|
||||
*/
|
||||
QByteArray readEntry( const QString& key );
|
||||
|
||||
/**
|
||||
* Returns whether the keychain has an entry with key @p key
|
||||
* error() and errorString() hold the result of the read operation.
|
||||
*
|
||||
* @param key the key to check for
|
||||
*/
|
||||
bool entryExists( const QString& key );
|
||||
|
||||
/**
|
||||
* Deletes the data for a @p key from the keychain.
|
||||
* error() and errorString() hold the result of the delete operation.
|
||||
|
|
|
@ -138,3 +138,25 @@ Keychain::Error Keychain::Private::deleteEntryImpl( const QString& account,
|
|||
return CouldNotDeleteEntry;
|
||||
}
|
||||
|
||||
|
||||
Keychain::Error Keychain::Private::entryExistsImpl( bool* exists,
|
||||
const QString& account,
|
||||
QString* err ) {
|
||||
Q_ASSERT( exists );
|
||||
*exists = false;
|
||||
SecKeychainItemRef ref;
|
||||
QByteArray pw;
|
||||
const OSStatus ret1 = readPw( &pw, service, account, &ref );
|
||||
if ( ret1 == errSecItemNotFound ) {
|
||||
return NoError;
|
||||
}
|
||||
if ( ret1 != noErr ) {
|
||||
*err = strForStatus( ret1 );
|
||||
//TODO map error code, set errstr
|
||||
return OtherError;
|
||||
}
|
||||
|
||||
CFRelease( ref );
|
||||
*exists = true;
|
||||
return NoError;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ public:
|
|||
Keychain::Error readEntryImpl( QByteArray* password,
|
||||
const QString& account,
|
||||
QString* errorString );
|
||||
|
||||
Keychain::Error entryExistsImpl( bool* exists,
|
||||
const QString& key,
|
||||
QString* errorString );
|
||||
const QString service;
|
||||
Keychain::Error error;
|
||||
QString errorString;
|
||||
|
|
|
@ -8,11 +8,42 @@
|
|||
*****************************************************************************/
|
||||
#include "keychain_p.h"
|
||||
|
||||
QString Keychain::Private::readPasswordImpl( const QString& account ) const {
|
||||
throw KeychainException( QLatin1String("not implemented") );
|
||||
using namespace QKeychain;
|
||||
|
||||
Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
|
||||
const QString& account,
|
||||
QString* err ) {
|
||||
Q_ASSERT( pw );
|
||||
Q_ASSERT( err );
|
||||
err->clear();
|
||||
*err = tr("Not implemented");
|
||||
return OtherError;
|
||||
}
|
||||
|
||||
void Keychain::Private::writePasswordImpl( const QString& account, const QString& password ) {
|
||||
throw KeychainException( QLatin1String("not implemented") );
|
||||
Keychain::Error Keychain::Private::writeEntryImpl( const QString& account,
|
||||
const QByteArray& data,
|
||||
QString* err ) {
|
||||
Q_ASSERT( err );
|
||||
err->clear();
|
||||
*err = tr("Not implemented");
|
||||
return OtherError;
|
||||
}
|
||||
|
||||
Keychain::Error Keychain::Private::deleteEntryImpl( const QString& account,
|
||||
QString* err ) {
|
||||
Q_ASSERT( err );
|
||||
err->clear();
|
||||
*err = tr("Not implemented");
|
||||
return OtherError;
|
||||
}
|
||||
|
||||
|
||||
Keychain::Error Keychain::Private::entryExistsImpl( bool* exists,
|
||||
const QString& account,
|
||||
QString* err ) {
|
||||
Q_ASSERT( exists );
|
||||
Q_ASSERT( err );
|
||||
err->clear();
|
||||
*err = tr("Not implemented");
|
||||
return OtherError;
|
||||
}
|
||||
|
|
8
lib.pro
8
lib.pro
|
@ -7,9 +7,13 @@ HEADERS += keychain.h \
|
|||
keychain_p.h
|
||||
SOURCES += keychain.cpp
|
||||
|
||||
|
||||
macx {
|
||||
LIBS += -framework Security -framework CoreFoundation
|
||||
SOURCES += keychain_mac.cpp
|
||||
}
|
||||
win32:SOURCES += keychain_win.cpp
|
||||
|
||||
win32 {
|
||||
DESTDIR = lib
|
||||
DLLDESTDIR = lib
|
||||
SOURCES += keychain_win.cpp
|
||||
}
|
||||
|
|
|
@ -7,5 +7,6 @@ QT -= gui
|
|||
CONFIG += console
|
||||
macx:CONFIG -= app_bundle
|
||||
|
||||
LIBS += -L$$OUT_PWD -lqtkeychain
|
||||
win32:LIBS += -Llib -lqtkeychain
|
||||
unix:LIBS += -L$$OUT_PWD -lqtkeychain
|
||||
|
||||
|
|
Loading…
Reference in New Issue