aboutsummaryrefslogtreecommitdiffstats
path: root/gpgwin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gpgwin.cpp')
-rw-r--r--gpgwin.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/gpgwin.cpp b/gpgwin.cpp
index f7b83f1..0126fe5 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -384,13 +384,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());