diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-12-28 15:47:04 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2011-12-28 15:47:04 +0000 |
commit | cffc559b76b048297f51b2aebe497776eafbf2f8 (patch) | |
tree | b8bb6c3f75d8d2e71e8e5fc85b2c3ded1e793817 /gpgcontext.cpp | |
parent | fix utf8 decoding of gpg-error messages (diff) | |
download | gpg4usb-cffc559b76b048297f51b2aebe497776eafbf2f8.tar.gz gpg4usb-cffc559b76b048297f51b2aebe497776eafbf2f8.zip |
show useful error message when no matching private key for decryption found
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@709 34ebc366-c3a9-4b3c-9f84-69acf7962910
Diffstat (limited to 'gpgcontext.cpp')
-rw-r--r-- | gpgcontext.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/gpgcontext.cpp b/gpgcontext.cpp index d5c9df8..76ba5b3 100644 --- a/gpgcontext.cpp +++ b/gpgcontext.cpp @@ -360,6 +360,7 @@ bool GpgContext::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer) { gpgme_data_t in = 0, out = 0; gpgme_decrypt_result_t result = 0; + QString errorString; outBuffer->resize(0); if (mCtx) { @@ -371,6 +372,18 @@ bool GpgContext::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer) if (!err) { err = gpgme_op_decrypt(mCtx, in, out); checkErr(err); + + if(err) { + errorString.append(gpgErrString(err)).append("<br>"); + result = gpgme_op_decrypt_result(mCtx); + checkErr(result->recipients->status); + errorString.append(gpgErrString(result->recipients->status)).append("<br>"); + + errorString.append(tr("<br>No private key with id ")) + .append(result->recipients->keyid) + .append(tr(" in keyring.")); + } + if (!err) { result = gpgme_op_decrypt_result(mCtx); if (result->unsupported_algorithm) { @@ -384,7 +397,7 @@ bool GpgContext::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer) } } if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) { - QMessageBox::critical(0, tr("Error decrypting:"), QString::fromUtf8(gpgme_strerror(err))); + QMessageBox::critical(0, tr("Error decrypting:"), errorString); return false; } @@ -515,7 +528,7 @@ int GpgContext::checkErr(gpgme_error_t err, QString comment) const { //if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) { if (err != GPG_ERR_NO_ERROR) { - qDebug() << "[Error " << comment << "] Source: " << gpgme_strsource(err) << " String: " << QString::fromUtf8(gpgme_strerror(err)); + qDebug() << "[Error " << comment << "] Source: " << gpgme_strsource(err) << " String: " << gpgErrString(err); } return err; } @@ -524,11 +537,14 @@ int GpgContext::checkErr(gpgme_error_t err) const { //if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) { if (err != GPG_ERR_NO_ERROR) { - qDebug() << "[Error] Source: " << gpgme_strsource(err) << " String: " << QString::fromUtf8(gpgme_strerror(err)); + qDebug() << "[Error] Source: " << gpgme_strsource(err) << " String: " << gpgErrString(err); } return err; } +QString GpgContext::gpgErrString(gpgme_error_t err) { + return QString::fromUtf8(gpgme_strerror(err)); +} /** export private key, TODO errohandling, e.g. like in seahorse (seahorse-gpg-op.c) **/ |