aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-08-27 13:53:43 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-08-27 13:53:43 +0000
commitd97fa22ec56017842e38856df04f38d3de0e12dd (patch)
tree9bdbdf7f1f47621bd1c308398a26687d4309c0ef
parentbit more specific help text (diff)
downloadgpg4usb-d97fa22ec56017842e38856df04f38d3de0e12dd.tar.gz
gpg4usb-d97fa22ec56017842e38856df04f38d3de0e12dd.zip
fix bug that crashes windows-build when encrypting twice
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@366 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--context.cpp39
-rw-r--r--context.h2
2 files changed, 24 insertions, 17 deletions
diff --git a/context.cpp b/context.cpp
index 09e4e57..2630ee1 100644
--- a/context.cpp
+++ b/context.cpp
@@ -313,14 +313,18 @@ bool Context::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer)
}
}
if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) {
- QMessageBox::critical(0, "Error encrypting:", gpgme_strerror(err));
+ QMessageBox::critical(0, "Error decrypting:", gpgme_strerror(err));
}
- if (err != GPG_ERR_NO_ERROR)
- clearCache();
- if (in)
+ //if (err != GPG_ERR_NO_ERROR)
+ // always clear password cache. TODO: implement passwort save
+ clearCache();
+
+ if (in) {
gpgme_data_release(in);
- if (out)
+ }
+ if (out) {
gpgme_data_release(out);
+ }
return (err == GPG_ERR_NO_ERROR);
}
@@ -388,24 +392,25 @@ gpgme_error_t Context::passphrase(const char *uid_hint,
s += "<b>Enter Password for</b><br>\n" + gpg_hint + "\n";
}
- if (m_cache.isEmpty()) {
+ if (mPasswordCache.isEmpty()) {
QString password = QInputDialog::getText(0, "Enter Password",
s, QLineEdit::Password,
"", &result, Qt::Window);
- if (result) m_cache = password.toAscii();
- } else
- result = false;
+ if (result) mPasswordCache = password.toAscii();
+ } else {
+ result = true;
+ }
if (result) {
#ifndef _WIN32
- if (write(fd, m_cache.data(), m_cache.length()) == -1) {
+ if (write(fd, mPasswordCache.data(), mPasswordCache.length()) == -1) {
qDebug() << "something is terribly broken";
}
#else
DWORD written;
- WriteFile((HANDLE) fd, m_cache.data(), m_cache.length(), &written, 0);
+ WriteFile((HANDLE) fd, mPasswordCache.data(), mPasswordCache.length(), &written, 0);
#endif
returnValue = 0;
@@ -426,23 +431,25 @@ gpgme_error_t Context::passphrase(const char *uid_hint,
/** also from kgpgme.cpp, seems to clear password from mem */
void Context::clearCache()
{
- if (m_cache.size() > 0) {
- m_cache.fill('\0');
- m_cache.truncate(0);
+ if (mPasswordCache.size() > 0) {
+ mPasswordCache.fill('\0');
+ mPasswordCache.truncate(0);
}
}
// error-handling
void Context::checkErr(gpgme_error_t err, QString comment) const
{
- if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) {
+ //if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) {
+ if (err != GPG_ERR_NO_ERROR) {
qDebug() << "[Error " << comment << "] Source: " << gpgme_strsource(err) << " String: " << gpgme_strerror(err);
}
}
void Context::checkErr(gpgme_error_t err) const
{
- if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) {
+ //if (err != GPG_ERR_NO_ERROR && err != GPG_ERR_CANCELED) {
+ if (err != GPG_ERR_NO_ERROR) {
qDebug() << "[Error] Source: " << gpgme_strsource(err) << " String: " << gpgme_strerror(err);
}
}
diff --git a/context.h b/context.h
index 5acc04b..234ec5b 100644
--- a/context.h
+++ b/context.h
@@ -79,7 +79,7 @@ private:
gpgme_data_t in, out;
gpgme_error_t err;
gpgme_error_t readToBuffer(gpgme_data_t in, QByteArray *outBuffer);
- QByteArray m_cache;
+ QByteArray mPasswordCache;
bool debug;
void checkErr(gpgme_error_t err) const;
void checkErr(gpgme_error_t err, QString comment) const;