aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2008-09-11 14:51:08 +0200
committernils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2008-09-11 14:51:08 +0200
commit8cb430b0413887bc22e7c09c8aca0ff4d931bb70 (patch)
tree29d6edf1082c3b71d630323f19d6825c67ad6651
parentadded import key dialog (diff)
downloadgpg4usb-8cb430b0413887bc22e7c09c8aca0ff4d931bb70.tar.gz
gpg4usb-8cb430b0413887bc22e7c09c8aca0ff4d931bb70.zip
simple fix for 'NO DATA'-error
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@157 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--gpgwin.cpp17
-rw-r--r--gpgwin.h1
2 files changed, 17 insertions, 1 deletions
diff --git a/gpgwin.cpp b/gpgwin.cpp
index 41df8f3..34baee8 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -398,13 +398,28 @@ void GpgWin::encrypt()
void GpgWin::decrypt()
{
QByteArray *tmp = new QByteArray();
- myCtx->decrypt(edit->toPlainText().toAscii(), tmp);
+ QByteArray text = edit->toPlainText().toAscii();
+ preventNoDataErr(&text);
+ myCtx->decrypt(text, tmp);
if (!tmp->isEmpty()) {
QString *tmp2 = new QString(*tmp);
edit->setPlainText(*tmp2);
}
}
+/**
+ * if there is no '\n' before the PGP-Begin-Block, but for example a whitespace,
+ * GPGME doesn't recognise the Message as encrypted. This function adds '\n'
+ * before the PGP-Begin-Block, if missing.
+ */
+void GpgWin::preventNoDataErr(QByteArray *in)
+{
+ int block_start = in->indexOf("-----BEGIN PGP MESSAGE-----");
+ if(block_start > 0 && in->at(block_start - 1) != '\n') {
+ in->insert(block_start, '\n');
+ }
+}
+
void GpgWin::importKeyFromEdit()
{
myCtx->importKey(edit->toPlainText().toAscii());
diff --git a/gpgwin.h b/gpgwin.h
index 9e40750..995662f 100644
--- a/gpgwin.h
+++ b/gpgwin.h
@@ -69,6 +69,7 @@ private:
void setCurrentFile(const QString &fileName);
bool maybeSave();
QString strippedName(const QString &fullFileName);
+ void preventNoDataErr(QByteArray *in);
QPlainTextEdit *edit;
QMenu *fileMenu;