aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2011-08-23 19:42:09 +0000
committernils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2011-08-23 19:42:09 +0000
commit5041e5fb42cd245590c0ba593c8e9427d63038fe (patch)
tree8d53be9a3a88056e3c96cddcff385d7d089f91d5
parentshow appropriate filename in key export to file (diff)
downloadgpg4usb-5041e5fb42cd245590c0ba593c8e9427d63038fe.tar.gz
gpg4usb-5041e5fb42cd245590c0ba593c8e9427d63038fe.zip
ignore whitespaces at end and before text when checking, if message is completely signed
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@520 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--TODO2
-rw-r--r--context.cpp2
-rw-r--r--gpgwin.cpp123
3 files changed, 61 insertions, 66 deletions
diff --git a/TODO b/TODO
index a8acf12..b42645c 100644
--- a/TODO
+++ b/TODO
@@ -12,7 +12,7 @@ Release 0.3.1
- in verifycation dialog import multiple keys
- inform user about verification errors
- enum for verify status [DONE]
-- put sign/verify to toolbar and add shortcuts
+- put sign/verify to toolbar and add shortcuts [DONE]
- umlaute are not handled correctly in signing
- beautify icons for verify and sign
diff --git a/context.cpp b/context.cpp
index c6f2dd4..733897e 100644
--- a/context.cpp
+++ b/context.cpp
@@ -495,7 +495,6 @@ void Context::executeGpgCommand(QStringList arguments, QByteArray *stdOut, QByte
*stdErr = gpg.readAllStandardError();
}
-
/***
* TODO: return type should contain:
* -> list of sigs
@@ -579,7 +578,6 @@ void Context::sign(const QByteArray &inBuffer, QByteArray *outBuffer) {
err = readToBuffer(out, outBuffer);
qDebug() << "sig: " << QString::fromUtf8(*outBuffer);
-
}
bool Context::sign(QStringList *uidList, const QByteArray &inBuffer, QByteArray *outBuffer ) {
diff --git a/gpgwin.cpp b/gpgwin.cpp
index 3b0642b..937ccb8 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -516,63 +516,6 @@ void GpgWin::openTutorial() {
QDesktopServices::openUrl(QUrl("http://gpg4usb.cpunk.de/docu.html"));
}
-void GpgWin::encrypt()
-{
- QStringList *uidList = mKeyList->getChecked();
-
- QByteArray *tmp = new QByteArray();
- if (mCtx->encrypt(uidList, edit->curTextPage()->toPlainText().toUtf8(), tmp)) {
- QString *tmp2 = new QString(*tmp);
-
- // beginEditBlock and endEditBlock() let operation look like single undo/redo operation
- QTextCursor cursor(edit->curTextPage()->document());
- cursor.beginEditBlock();
- edit->curTextPage()->selectAll();
- edit->curTextPage()->insertPlainText(*tmp2);
- cursor.endEditBlock();
- }
-}
-
-void GpgWin::decrypt()
-{
- QByteArray *decrypted = new QByteArray();
- QByteArray text = edit->curTextPage()->toPlainText().toAscii(); // TODO: toUtf8() here?
- preventNoDataErr(&text);
-
- // try decrypt, if fail do nothing, especially don't replace text
- if(!mCtx->decrypt(text, decrypted)) {
- return;
- }
-
- /**
- * 1) is it mime (content-type:)
- * 2) parse header
- * 2) choose action depending on content-type
- */
- if(Mime::isMime(decrypted)) {
- Header header = Mime::getHeader(decrypted);
- // is it multipart, is multipart-parsing enabled
- if(header.getValue("Content-Type") == "multipart/mixed"
- && settings.value("mime/parseMime").toBool()) {
- parseMime(decrypted);
- } else if(header.getValue("Content-Type") == "text/plain"
- && settings.value("mime/parseQP").toBool()){
- if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") {
- QByteArray *decoded = new QByteArray();
- Mime::quotedPrintableDecode(*decrypted, *decoded);
- //TODO: remove header
- decrypted = decoded;
- }
- }
- }
- // beginEditBlock and endEditBlock() let operation look like single undo/redo operation
- QTextCursor cursor(edit->curTextPage()->document());
- cursor.beginEditBlock();
- edit->curTextPage()->selectAll();
- edit->curTextPage()->insertPlainText(QString::fromUtf8(*decrypted));
- cursor.endEditBlock();
-}
-
/**
* if this is mime, split text and attachments...
* message contains only text afterwards
@@ -693,18 +636,31 @@ void GpgWin::openKeyManagement()
keyMgmt->activateWindow();
}
-void GpgWin::sign()
+void GpgWin::encrypt()
{
- // test-stuff that does not belong here ;-)
- //mCtx->verify(QByteArray());
- //mCtx->sign(QByteArray(), new QByteArray());
- // end of test
+ QStringList *uidList = mKeyList->getChecked();
+
+ QByteArray *tmp = new QByteArray();
+ if (mCtx->encrypt(uidList, edit->curTextPage()->toPlainText().toUtf8(), tmp)) {
+ QString *tmp2 = new QString(*tmp);
+ // beginEditBlock and endEditBlock() let operation look like single undo/redo operation
+ QTextCursor cursor(edit->curTextPage()->document());
+ cursor.beginEditBlock();
+ edit->curTextPage()->selectAll();
+ edit->curTextPage()->insertPlainText(*tmp2);
+ cursor.endEditBlock();
+ }
+}
+
+void GpgWin::sign()
+{
QStringList *uidList = mKeyList->getChecked();
QByteArray *tmp = new QByteArray();
if (mCtx->sign(uidList, edit->curTextPage()->toPlainText().toUtf8(), tmp)) {
QString *tmp2 = new QString(*tmp);
+
// beginEditBlock and endEditBlock() let operation look like single undo/redo operation
QTextCursor cursor(edit->curTextPage()->document());
cursor.beginEditBlock();
@@ -713,6 +669,47 @@ void GpgWin::sign()
cursor.endEditBlock();
}
}
+
+void GpgWin::decrypt()
+{
+ QByteArray *decrypted = new QByteArray();
+ QByteArray text = edit->curTextPage()->toPlainText().toAscii(); // TODO: toUtf8() here?
+ preventNoDataErr(&text);
+
+ // try decrypt, if fail do nothing, especially don't replace text
+ if(!mCtx->decrypt(text, decrypted)) {
+ return;
+ }
+
+ /**
+ * 1) is it mime (content-type:)
+ * 2) parse header
+ * 2) choose action depending on content-type
+ */
+ if(Mime::isMime(decrypted)) {
+ Header header = Mime::getHeader(decrypted);
+ // is it multipart, is multipart-parsing enabled
+ if(header.getValue("Content-Type") == "multipart/mixed"
+ && settings.value("mime/parseMime").toBool()) {
+ parseMime(decrypted);
+ } else if(header.getValue("Content-Type") == "text/plain"
+ && settings.value("mime/parseQP").toBool()){
+ if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") {
+ QByteArray *decoded = new QByteArray();
+ Mime::quotedPrintableDecode(*decrypted, *decoded);
+ //TODO: remove header
+ decrypted = decoded;
+ }
+ }
+ }
+ // beginEditBlock and endEditBlock() let operation look like single undo/redo operation
+ QTextCursor cursor(edit->curTextPage()->document());
+ cursor.beginEditBlock();
+ edit->curTextPage()->selectAll();
+ edit->curTextPage()->insertPlainText(QString::fromUtf8(*decrypted));
+ cursor.endEditBlock();
+}
+
/*
* isSigned returns:
* - 0, if text isn't signed at all
@@ -720,7 +717,7 @@ void GpgWin::sign()
* - 2, if text is completly signed
*/
int GpgWin::isSigned(const QByteArray &text) {
- if (text.startsWith("-----BEGIN PGP SIGNED MESSAGE-----") && text.endsWith("-----END PGP SIGNATURE-----")) {
+ if (text.trimmed().startsWith("-----BEGIN PGP SIGNED MESSAGE-----") && text.trimmed().endsWith("-----END PGP SIGNATURE-----")) {
return 2;
}
if (text.contains("-----BEGIN PGP SIGNED MESSAGE-----") && text.contains("-----END PGP SIGNATURE-----")) {