always overwrite entries, remove flag to control that
This commit is contained in:
parent
ca40208439
commit
653bf190f0
|
@ -32,13 +32,13 @@ QString Keychain::errorString() const {
|
|||
return d->errorString;
|
||||
}
|
||||
|
||||
void Keychain::writePassword( const QString &key, const QString &password, OverwriteMode om ) {
|
||||
writeEntry( key, password.toUtf8(), om );
|
||||
void Keychain::writePassword( const QString &key, const QString &password ) {
|
||||
writeEntry( key, password.toUtf8() );
|
||||
}
|
||||
|
||||
void Keychain::writeEntry( const QString& key, const QByteArray& ba, OverwriteMode om ) {
|
||||
void Keychain::writeEntry( const QString& key, const QByteArray& ba ) {
|
||||
QString err;
|
||||
const Error ret = d->writeEntryImpl( key, ba, om, &err );
|
||||
const Error ret = d->writeEntryImpl( key, ba, &err );
|
||||
d->error = ret;
|
||||
d->errorString = err;
|
||||
}
|
||||
|
|
14
keychain.h
14
keychain.h
|
@ -50,14 +50,6 @@ public:
|
|||
OtherError /**< Something else went wrong (errorString() might provide details) */
|
||||
};
|
||||
|
||||
/**
|
||||
* Overwrite mode when writing passwords to the keychain
|
||||
*/
|
||||
enum OverwriteMode {
|
||||
DoNotOverwrite, /**< Do not overwrite existing entries */
|
||||
ForceOverwrite /**< Replace old data by new one */
|
||||
};
|
||||
|
||||
/**
|
||||
* The service name used as identifier.
|
||||
*/
|
||||
|
@ -82,8 +74,7 @@ public:
|
|||
* @param om Whether to overwrite existing passwords
|
||||
*/
|
||||
void writePassword( const QString& key,
|
||||
const QString& password,
|
||||
OverwriteMode om=DoNotOverwrite );
|
||||
const QString& password );
|
||||
|
||||
/**
|
||||
* Stores @p data in the keychain, for a given @p key.
|
||||
|
@ -94,8 +85,7 @@ public:
|
|||
* @param om Whether to overwrite existing passwords
|
||||
*/
|
||||
void writeEntry( const QString& key,
|
||||
const QByteArray& data,
|
||||
OverwriteMode om=DoNotOverwrite );
|
||||
const QByteArray& data );
|
||||
|
||||
/**
|
||||
* Reads the password for a given @p key from the keychain.
|
||||
|
|
|
@ -82,7 +82,6 @@ Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
|
|||
|
||||
Keychain::Error Keychain::Private::writeEntryImpl( const QString& account,
|
||||
const QByteArray& data,
|
||||
Keychain::OverwriteMode ov,
|
||||
QString* err ) {
|
||||
Q_ASSERT( err );
|
||||
err->clear();
|
||||
|
@ -101,15 +100,11 @@ Keychain::Error Keychain::Private::writeEntryImpl( const QString& account,
|
|||
switch ( ret ) {
|
||||
case errSecDuplicateItem:
|
||||
{
|
||||
if ( ov == Keychain::DoNotOverwrite ) {
|
||||
*err = tr("Entry already exists");
|
||||
return EntryAlreadyExists;
|
||||
}
|
||||
Error derr = deleteEntryImpl( account, err );
|
||||
if ( derr != NoError )
|
||||
return CouldNotDeleteEntry;
|
||||
else
|
||||
return writeEntryImpl( account, data, ov, err );
|
||||
return writeEntryImpl( account, data, err );
|
||||
}
|
||||
default:
|
||||
*err = strForStatus( ret );
|
||||
|
|
|
@ -21,7 +21,6 @@ public:
|
|||
|
||||
Keychain::Error writeEntryImpl( const QString& account,
|
||||
const QByteArray& data,
|
||||
Keychain::OverwriteMode,
|
||||
QString* errorString );
|
||||
Keychain::Error deleteEntryImpl( const QString& account,
|
||||
QString* errorString );
|
||||
|
|
|
@ -40,7 +40,7 @@ int main( int argc, char** argv ) {
|
|||
if ( ++it != args.constEnd() )
|
||||
return printUsage();
|
||||
Keychain k( QLatin1String("qtkeychain-testclient") );
|
||||
k.writePassword( acc, pass, Keychain::ForceOverwrite );
|
||||
k.writePassword( acc, pass );
|
||||
if ( k.error() ) {
|
||||
std::cerr << "Storing password failed: " << qPrintable(k.errorString()) << std::endl;
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue