[git] GPGME - branch, master, updated. gpgme-1.6.0-280-g105f544

by Andre Heinecke cvs at cvs.gnupg.org
Thu Aug 11 18:00:17 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  105f5446e69db00291164397cf0d8e68374cf420 (commit)
       via  59e2251a083b0ed61b3ab6d47015cef7cc6ceb05 (commit)
       via  8c5abc8d932affab4bc79a85e3f98f6f6b982ae8 (commit)
      from  b7d99e02188b7907b09fec3032fc1fd82fc2668a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 105f5446e69db00291164397cf0d8e68374cf420
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Aug 11 17:57:14 2016 +0200

    Qt: Add DefaultKeyGenerationJob
    
    * lang/qt/src/defaultkeygenerationjob.cpp,
    lang/qt/src/defaultkeygenerationjob.h: New.
    * lang/qt/src/Makefile.am: Update accordingly.
    
    --
    The defaultkeygenerationjob makes it easier to just generate a key
    in the future this should probably use quick-gen key but since this
    is not exposed in gpgme we hardcode the defaults and do it with
    the params file.
    
    This is also the first job that uses a new and better architecture
    without backend abstraction and the pimpl pattern instead of
    a specialized subclass.
    
    This is an adoption of kde's libkleo commit f49b7157
    Thanks dvratil at kde.org

diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am
index 59d8abc..840557e 100644
--- a/lang/qt/src/Makefile.am
+++ b/lang/qt/src/Makefile.am
@@ -33,7 +33,8 @@ qgpgme_sources = \
     qgpgmesecretkeyexportjob.cpp qgpgmesignencryptjob.cpp \
     qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \
     qgpgmeverifyopaquejob.cpp threadedjobmixin.cpp \
-    qgpgmekeyformailboxjob.cpp gpgme_backend_debug.cpp
+    qgpgmekeyformailboxjob.cpp gpgme_backend_debug.cpp \
+    defaultkeygenerationjob.cpp
 
 # If you add one here make sure that you also add one in camelcase
 qgpgme_headers= \
@@ -66,7 +67,8 @@ qgpgme_headers= \
     keygenerationjob.h \
     keylistjob.h \
     listallkeysjob.h \
-    verifydetachedjob.h
+    verifydetachedjob.h \
+    defaultkeygenerationjob.h
 
 camelcase_headers= \
     AddUserIDJob \
@@ -97,7 +99,8 @@ camelcase_headers= \
     KeyListJob \
     ListAllKeysJob \
     VerifyDetachedJob \
-    KeyForMailboxJob
+    KeyForMailboxJob \
+    DefaultKeyGenerationJob
 
 private_qgpgme_headers = \
     qgpgme_export.h \
@@ -180,7 +183,8 @@ qgpgme_moc_sources = \
     verifydetachedjob.moc \
     verifyopaquejob.moc \
     keyformailboxjob.moc \
-    qgpgmekeyformailboxjob.moc
+    qgpgmekeyformailboxjob.moc \
+    defaultkeygenerationjob.moc
 
 qgpgmeincludedir = $(includedir)/qgpgme
 qgpgmeinclude_HEADERS = $(qgpgme_headers)
diff --git a/lang/qt/src/defaultkeygenerationjob.cpp b/lang/qt/src/defaultkeygenerationjob.cpp
new file mode 100644
index 0000000..727eabb
--- /dev/null
+++ b/lang/qt/src/defaultkeygenerationjob.cpp
@@ -0,0 +1,123 @@
+/* defaultkeygenerationjob.cpp
+
+    Copyright (c) 2016 Klarälvdalens Datakonsult AB
+
+    QGpgME is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+
+    QGpgME is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of this program with any edition of
+    the Qt library by Trolltech AS, Norway (or with modified versions
+    of Qt that use the same license as Qt), and distribute linked
+    combinations including the two.  You must obey the GNU General
+    Public License in all respects for all of the code used other than
+    Qt.  If you modify this file, you may extend this exception to
+    your version of the file, but you are not obligated to do so.  If
+    you do not wish to do so, delete this exception statement from
+    your version.
+*/
+
+#include "defaultkeygenerationjob.h"
+#include "protocol.h"
+#include "keygenerationjob.h"
+
+#include <QPointer>
+#include <QEvent>
+
+using namespace QGpgME;
+
+namespace QGpgME {
+
+class DefaultKeyGenerationJob::Private
+{
+public:
+    Private()
+    {}
+
+    ~Private()
+    {
+        if (job) {
+            job->deleteLater();
+        }
+    }
+
+    QPointer<KeyGenerationJob> job;
+};
+}
+
+
+DefaultKeyGenerationJob::DefaultKeyGenerationJob(QObject* parent)
+    : Job(parent)
+    , d(new DefaultKeyGenerationJob::Private())
+{
+}
+
+DefaultKeyGenerationJob::~DefaultKeyGenerationJob()
+{
+    delete d;
+}
+
+QString DefaultKeyGenerationJob::auditLogAsHtml() const
+{
+    return d->job ? d->job->auditLogAsHtml() : QString();
+}
+
+GpgME::Error DefaultKeyGenerationJob::auditLogError() const
+{
+    return d->job ? d->job->auditLogError() : GpgME::Error();
+}
+
+void DefaultKeyGenerationJob::slotCancel()
+{
+    if (d->job) {
+        d->job->slotCancel();
+    }
+}
+
+GpgME::Error DefaultKeyGenerationJob::start(const QString &email, const QString &name)
+{
+    const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
+                                        "%ask-passphrase\n"
+                                        "key-type:      RSA\n"
+                                        "key-length:    2048\n"
+                                        "key-usage:     sign\n"
+                                        "subkey-type:   RSA\n"
+                                        "subkey-length: 2048\n"
+                                        "subkey-usage:  encrypt\n"
+                                        "name-email:    %1\n"
+                                        "name-real:     %2\n"
+                                        "</GnupgKeyParms>").arg(email, name);
+
+    d->job = openpgp()->keyGenerationJob();
+    d->job->installEventFilter(this);
+    connect(d->job, &KeyGenerationJob::result,
+            this, &DefaultKeyGenerationJob::result);
+    connect(d->job, &KeyGenerationJob::done,
+            this, &DefaultKeyGenerationJob::done);
+    connect(d->job, &KeyGenerationJob::done,
+            this, &QObject::deleteLater);
+    return d->job->start(args);
+}
+
+bool DefaultKeyGenerationJob::eventFilter(QObject *watched, QEvent *event)
+{
+    // Intercept the KeyGenerationJob's deferred delete event. We want the job
+    // to live at least as long as we do so we can delegate calls to it. We will
+    // delete the job manually afterwards.
+    if (watched == d->job && event->type() == QEvent::DeferredDelete) {
+        return true;
+    }
+
+    return Job::eventFilter(watched, event);
+}
diff --git a/lang/qt/src/defaultkeygenerationjob.h b/lang/qt/src/defaultkeygenerationjob.h
new file mode 100644
index 0000000..5b7334c
--- /dev/null
+++ b/lang/qt/src/defaultkeygenerationjob.h
@@ -0,0 +1,76 @@
+/* defaultkeygenerationjob.h
+
+    Copyright (c) 2016 Klarälvdalens Datakonsult AB
+
+    QGpgME is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+
+    QGpgME is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of this program with any edition of
+    the Qt library by Trolltech AS, Norway (or with modified versions
+    of Qt that use the same license as Qt), and distribute linked
+    combinations including the two.  You must obey the GNU General
+    Public License in all respects for all of the code used other than
+    Qt.  If you modify this file, you may extend this exception to
+    your version of the file, but you are not obligated to do so.  If
+    you do not wish to do so, delete this exception statement from
+    your version.
+*/
+#ifndef QGPGME_DEFAULTKEYGENERATION_H
+#define QGPGME_DEFAULTKEYGENERATION_H
+
+#include "job.h"
+
+#include "qgpgme_export.h"
+
+namespace GpgME {
+class KeyGenerationResult;
+}
+
+namespace QGpgME{
+
+/**
+ * Generates a PGP RSA/2048 bit key pair for given name and email address.
+ */
+class QGPGME_EXPORT DefaultKeyGenerationJob : public Job
+{
+    Q_OBJECT
+public:
+    explicit DefaultKeyGenerationJob(QObject *parent = Q_NULLPTR);
+    ~DefaultKeyGenerationJob();
+
+    GpgME::Error start(const QString &email, const QString &name);
+
+    QString auditLogAsHtml() const Q_DECL_OVERRIDE;
+    GpgME::Error auditLogError() const Q_DECL_OVERRIDE;
+
+
+public Q_SLOTS:
+    void slotCancel() Q_DECL_OVERRIDE;
+
+Q_SIGNALS:
+    void result(const GpgME::KeyGenerationResult &result, const QByteArray &pubkeyData,
+                const QString &auditLogAsHtml, const GpgME::Error &auditLogError);
+
+protected:
+    bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
+
+private:
+    class Private;
+    Private * const d;
+};
+
+}
+
+#endif

commit 59e2251a083b0ed61b3ab6d47015cef7cc6ceb05
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Aug 11 17:38:36 2016 +0200

    Qt: Ensure all public classes are exported
    
    * src/abstractimportjob.h,
    src/cryptoconfig.h,
    src/deletejob.h,
    src/exportjob.h,
    src/importfromkeyserverjob.h,
    src/importjob.h,
    src/keygenerationjob.h,
    src/keylistjob.h,
    src/listallkeysjob.h,
    src/refreshkeysjob.h,
    src/signencryptjob.h,
    src/specialjob.h,
    src/verifydetachedjob.h: Export classes.
    
    --
    This is an adoption of kde's libkleo commit: d6a71a4e
    Thanks dvratil at kde.org

diff --git a/lang/qt/src/abstractimportjob.h b/lang/qt/src/abstractimportjob.h
index 33f6a2a..572f203 100644
--- a/lang/qt/src/abstractimportjob.h
+++ b/lang/qt/src/abstractimportjob.h
@@ -36,6 +36,8 @@
 
 #include "job.h"
 
+#include "qgpgme_export.h"
+
 namespace GpgME
 {
 class Error;
@@ -45,7 +47,7 @@ class ImportResult;
 namespace QGpgME
 {
 
-class AbstractImportJob : public Job
+class QGPGME_EXPORT AbstractImportJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/cryptoconfig.h b/lang/qt/src/cryptoconfig.h
index 858dbb7..c3f0c7e 100644
--- a/lang/qt/src/cryptoconfig.h
+++ b/lang/qt/src/cryptoconfig.h
@@ -34,6 +34,7 @@
 #ifndef CRYPTOCONFIG_H
 #define CRYPTOCONFIG_H
 
+#include "qgpgme_export.h"
 #ifdef __cplusplus
 /* we read this file from a C compiler, and are only interested in the
  * enums... */
@@ -50,7 +51,7 @@ namespace QGpgME
 /**
  * Description of a single option
  */
-class CryptoConfigEntry
+class QGPGME_EXPORT CryptoConfigEntry
 {
 
 public:
@@ -252,7 +253,7 @@ public:
 /**
  * Group containing a set of config options
  */
-class CryptoConfigGroup
+class QGPGME_EXPORT CryptoConfigGroup
 {
 
 public:
@@ -301,7 +302,7 @@ public:
 /**
  * Crypto config for one component (e.g. gpg-agent, dirmngr etc.)
  */
-class CryptoConfigComponent
+class QGPGME_EXPORT CryptoConfigComponent
 {
 
 public:
@@ -341,7 +342,7 @@ public:
 /**
  * Main interface to crypto configuration.
  */
-class CryptoConfig
+class QGPGME_EXPORT CryptoConfig
 {
 
 public:
diff --git a/lang/qt/src/deletejob.h b/lang/qt/src/deletejob.h
index 1f4e8cf..f8479b1 100644
--- a/lang/qt/src/deletejob.h
+++ b/lang/qt/src/deletejob.h
@@ -34,6 +34,7 @@
 #ifndef __KLEO_DELETEJOB_H__
 #define __KLEO_DELETEJOB_H__
 
+#include "qgpgme_export.h"
 #include "job.h"
 
 namespace GpgME
@@ -58,7 +59,7 @@ namespace QGpgME
    After result() is emitted, the DeleteJob will schedule it's own
    destruction by calling QObject::deleteLater().
 */
-class DeleteJob : public Job
+class QGPGME_EXPORT DeleteJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/exportjob.h b/lang/qt/src/exportjob.h
index df21f03..583d4c0 100644
--- a/lang/qt/src/exportjob.h
+++ b/lang/qt/src/exportjob.h
@@ -34,6 +34,7 @@
 #ifndef __QGPGME_EXPORTJOB_H__
 #define __QGPGME_EXPORTJOB_H__
 
+#include "qgpgme_export.h"
 #include "job.h"
 
 #include <QtCore/QByteArray>
@@ -61,7 +62,7 @@ namespace QGpgME
    After result() is emitted, the ExportJob will schedule it's own
    destruction by calling QObject::deleteLater().
 */
-class ExportJob : public Job
+class QGPGME_EXPORT ExportJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/importfromkeyserverjob.h b/lang/qt/src/importfromkeyserverjob.h
index 7ab13cb..f548ea7 100644
--- a/lang/qt/src/importfromkeyserverjob.h
+++ b/lang/qt/src/importfromkeyserverjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_IMPORTFROMKEYSERVERJOB_H__
 
 #include "abstractimportjob.h"
+#include "qgpgme_export.h"
 
 namespace GpgME
 {
@@ -61,7 +62,7 @@ namespace QGpgME
    After result() is emitted, the ImportJob will schedule it's own
    destruction by calling QObject::deleteLater().
 */
-class ImportFromKeyserverJob : public AbstractImportJob
+class QGPGME_EXPORT ImportFromKeyserverJob : public AbstractImportJob
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/importjob.h b/lang/qt/src/importjob.h
index d9f60d1..5c7b24d 100644
--- a/lang/qt/src/importjob.h
+++ b/lang/qt/src/importjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_IMPORTJOB_H__
 
 #include "abstractimportjob.h"
+#include "qgpgme_export.h"
 
 #include <QtCore/QByteArray>
 
@@ -60,7 +61,7 @@ namespace QGpgME
    After result() is emitted, the ImportJob will schedule it's own
    destruction by calling QObject::deleteLater().
 */
-class ImportJob : public AbstractImportJob
+class QGPGME_EXPORT ImportJob : public AbstractImportJob
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/keygenerationjob.h b/lang/qt/src/keygenerationjob.h
index 90f29bf..a0beeac 100644
--- a/lang/qt/src/keygenerationjob.h
+++ b/lang/qt/src/keygenerationjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_KEYGENERATIONJOB_H__
 
 #include "job.h"
+#include "qgpgme_export.h"
 
 #include <QtCore/QByteArray>
 
@@ -60,7 +61,7 @@ namespace QGpgME
    After result() is emitted, the KeyGenerationJob will schedule it's own
    destruction by calling QObject::deleteLater().
 */
-class KeyGenerationJob : public Job
+class QGPGME_EXPORT KeyGenerationJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/keylistjob.h b/lang/qt/src/keylistjob.h
index 6e62c4f..fc7a048 100644
--- a/lang/qt/src/keylistjob.h
+++ b/lang/qt/src/keylistjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_KEYLISTJOB_H__
 
 #include "job.h"
+#include "qgpgme_export.h"
 
 #ifdef BUILDING_QGPGME
 # include "key.h"
@@ -70,7 +71,7 @@ namespace QGpgME
    KeyListJob will schedule it's own destruction by calling
    QObject::deleteLater().
 */
-class KeyListJob : public Job
+class QGPGME_EXPORT KeyListJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/listallkeysjob.h b/lang/qt/src/listallkeysjob.h
index 9d4711d..4fbb469 100644
--- a/lang/qt/src/listallkeysjob.h
+++ b/lang/qt/src/listallkeysjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_LISTALLKEYSJOB_H__
 
 #include "job.h"
+#include "qgpgme_export.h"
 
 #ifdef BUILDING_QGPGME
 # include "key.h"
@@ -69,7 +70,7 @@ namespace QGpgME
    This is potentially much faster than a KeyListJob with empty
    pattern.
 */
-class ListAllKeysJob : public Job
+class QGPGME_EXPORT ListAllKeysJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/refreshkeysjob.h b/lang/qt/src/refreshkeysjob.h
index d0bc51f..a97de80 100644
--- a/lang/qt/src/refreshkeysjob.h
+++ b/lang/qt/src/refreshkeysjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_REFRESHKEYSJOB_H__
 
 #include "job.h"
+#include "qgpgme_export.h"
 
 #include <vector>
 
@@ -62,7 +63,7 @@ namespace QGpgME
    After result() is emitted, the KeyListJob will schedule it's own
    destruction by calling QObject::deleteLater().
 */
-class RefreshKeysJob : public Job
+class QGPGME_EXPORT RefreshKeysJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/signencryptjob.h b/lang/qt/src/signencryptjob.h
index b0aafe3..4e07744 100644
--- a/lang/qt/src/signencryptjob.h
+++ b/lang/qt/src/signencryptjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_SIGNENCRYPTJOB_H__
 
 #include "job.h"
+#include "qgpgme_export.h"
 
 #ifdef BUILDING_QGPGME
 # include "global.h"
@@ -75,7 +76,7 @@ namespace QGpgME
    After result() is emitted, the SignEncryptJob will schedule it's
    own destruction by calling QObject::deleteLater().
 */
-class SignEncryptJob : public Job
+class QGPGME_EXPORT SignEncryptJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/specialjob.h b/lang/qt/src/specialjob.h
index 788371e..2c80f20 100644
--- a/lang/qt/src/specialjob.h
+++ b/lang/qt/src/specialjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_SPECIALJOB_H__
 
 #include "job.h"
+#include "qgpgme_export.h"
 
 namespace GpgME
 {
@@ -65,7 +66,7 @@ namespace QGpgME
    through the read-only result property, the latter of which needs
    to be defined in each SpecialJob subclass.
 */
-class SpecialJob : public Job
+class QGPGME_EXPORT SpecialJob : public Job
 {
     Q_OBJECT
 protected:
diff --git a/lang/qt/src/verifydetachedjob.h b/lang/qt/src/verifydetachedjob.h
index 0cb92e6..b339a8c 100644
--- a/lang/qt/src/verifydetachedjob.h
+++ b/lang/qt/src/verifydetachedjob.h
@@ -35,6 +35,7 @@
 #define __KLEO_VERIFYDETACHEDJOB_H__
 
 #include "job.h"
+#include "qgpgme_export.h"
 
 #include <memory>
 

commit 8c5abc8d932affab4bc79a85e3f98f6f6b982ae8
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Aug 11 17:22:35 2016 +0200

    Qt: Add KeyForMailboxJob
    
    * lang/qt/src/job.cpp: Include moc and make subclass.
    * lang/qt/src/keyformailboxjob.h,
    lang/qt/src/qgpgmekeyformailboxjob.cpp,
    lang/qt/src/qgpgmekeyformailboxjob.h: New.
    * lang/qt/tests/run-keyformailboxjob.cpp: New manual test.
    * lang/qt/tests/Makefile.am: Add run-keyformailboxjob.
    * lang/qt/src/Makefile.am: Update accordingly.
    * lang/qt/src/protocol.h, lang/qt/src/protocol_p.h: Add
    keyformailboxjob.
    
    --
    The KeyForMailboxjob can be used to determine the best key to
    use to encrypt something to a given mail address.

diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am
index ae316ba..59d8abc 100644
--- a/lang/qt/src/Makefile.am
+++ b/lang/qt/src/Makefile.am
@@ -33,7 +33,7 @@ qgpgme_sources = \
     qgpgmesecretkeyexportjob.cpp qgpgmesignencryptjob.cpp \
     qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \
     qgpgmeverifyopaquejob.cpp threadedjobmixin.cpp \
-    gpgme_backend_debug.cpp
+    qgpgmekeyformailboxjob.cpp gpgme_backend_debug.cpp
 
 # If you add one here make sure that you also add one in camelcase
 qgpgme_headers= \
@@ -49,6 +49,7 @@ qgpgme_headers= \
     exportjob.h \
     hierarchicalkeylistjob.h \
     job.h \
+    keyformailboxjob.h \
     multideletejob.h \
     protocol.h \
     qgpgme_export.h \
@@ -95,7 +96,8 @@ camelcase_headers= \
     KeyGenerationJob \
     KeyListJob \
     ListAllKeysJob \
-    VerifyDetachedJob
+    VerifyDetachedJob \
+    KeyForMailboxJob
 
 private_qgpgme_headers = \
     qgpgme_export.h \
@@ -124,6 +126,7 @@ private_qgpgme_headers = \
     qgpgmesignkeyjob.h \
     qgpgmeverifydetachedjob.h \
     qgpgmeverifyopaquejob.h \
+    qgpgmekeyformailboxjob.h \
     specialjob.h \
     threadedjobmixin.h
 
@@ -175,7 +178,9 @@ qgpgme_moc_sources = \
     signkeyjob.moc \
     specialjob.moc \
     verifydetachedjob.moc \
-    verifyopaquejob.moc
+    verifyopaquejob.moc \
+    keyformailboxjob.moc \
+    qgpgmekeyformailboxjob.moc
 
 qgpgmeincludedir = $(includedir)/qgpgme
 qgpgmeinclude_HEADERS = $(qgpgme_headers)
diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp
index 7ca1df9..8e50647 100644
--- a/lang/qt/src/job.cpp
+++ b/lang/qt/src/job.cpp
@@ -55,6 +55,7 @@
 #include "refreshkeysjob.h"
 #include "adduseridjob.h"
 #include "specialjob.h"
+#include "keyformailboxjob.h"
 
 #include <QCoreApplication>
 #include <QDebug>
@@ -120,6 +121,7 @@ make_job_subclass(DeleteJob)
 make_job_subclass(RefreshKeysJob)
 make_job_subclass(AddUserIDJob)
 make_job_subclass(SpecialJob)
+make_job_subclass(KeyForMailboxJob)
 
 #undef make_job_subclass
 
@@ -148,3 +150,4 @@ make_job_subclass(SpecialJob)
 #include "refreshkeysjob.moc"
 #include "adduseridjob.moc"
 #include "specialjob.moc"
+#include "keyformailboxjob.moc"
diff --git a/lang/qt/src/keyformailboxjob.h b/lang/qt/src/keyformailboxjob.h
new file mode 100644
index 0000000..9e76df5
--- /dev/null
+++ b/lang/qt/src/keyformailboxjob.h
@@ -0,0 +1,101 @@
+/*
+    keyformailboxjob.h
+
+    This file is part of qgpgme, the Qt API binding for gpgme
+    Copyright (c) 2016 Intevation GmbH
+
+    QGpgME is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+
+    QGpgME is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of this program with any edition of
+    the Qt library by Trolltech AS, Norway (or with modified versions
+    of Qt that use the same license as Qt), and distribute linked
+    combinations including the two.  You must obey the GNU General
+    Public License in all respects for all of the code used other than
+    Qt.  If you modify this file, you may extend this exception to
+    your version of the file, but you are not obligated to do so.  If
+    you do not wish to do so, delete this exception statement from
+    your version.
+*/
+#ifndef __KLEO_KEYFORMAILBOX_H__
+#define __KLEO_KEYFORMAILBOX_H__
+
+#include <QString>
+
+#include "job.h"
+
+#include <gpgme++/key.h>
+namespace GpgME
+{
+class Error;
+class KeyListResult;
+}
+
+namespace QGpgME
+{
+
+/**
+   @short Get the best key to use for a Mailbox
+
+   To use the keyformailboxjob, first obtain an instance from the
+   CryptoBackend and either exec it or start and
+   conncet the result() signals to a suitable slot.
+   The job will be automatically deleted in which
+   case the KeylistJob instance will have schedules it's own
+   destruction with a call to QObject::deleteLater().
+
+   The best key is defined as the key with a UID that has an
+   E-Mail that matches the mailbox provided. If multiple
+   keys are found the one with the highest validity is returned.
+
+   After result() is emitted, the
+   KeyListJob will schedule it's own destruction by calling
+   QObject::deleteLater().
+*/
+class QGPGME_EXPORT KeyForMailboxJob: public Job
+{
+    Q_OBJECT
+protected:
+    explicit KeyForMailboxJob(QObject *parent);
+
+public:
+    ~KeyForMailboxJob();
+
+    /**
+      Starts the operation. \a mailbox is the mailbox to
+      look for.
+
+      The result is the same as for the LocateKeysJob.
+
+      If \a canEncrypt is true, only keys that have a subkey for encryption
+      usage are returned. Use this if you need to select a
+      key for signing.
+    */
+    virtual GpgME::Error start(const QString &mailbox, bool canEncrypt = true) = 0;
+
+    virtual GpgME::KeyListResult exec(const QString &mailbox, bool canEncrypt, GpgME::Key &key, GpgME::UserID &uid) = 0;
+
+Q_SIGNALS:
+    /** The result. \a Key is the key found or a Null key.
+     *
+     * The userid is the uid where the mailbox matches.
+     *
+     * The auditlog params are always null / empty.
+     */
+    void result(const GpgME::KeyListResult &result, const GpgME::Key &key, const GpgME::UserID &uid, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error());
+};
+
+}
+#endif
diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h
index 64146b8..23b9d93 100644
--- a/lang/qt/src/protocol.h
+++ b/lang/qt/src/protocol.h
@@ -62,6 +62,7 @@ class ChangeOwnerTrustJob;
 class ChangePasswdJob;
 class AddUserIDJob;
 class SpecialJob;
+class KeyForMailboxJob;
 
 /** The main entry point for QGpgME Comes in OpenPGP and SMIME(CMS) flavors.
  *
@@ -145,6 +146,8 @@ public:
      * with both includeSigs and validate options.
      */
     virtual KeyListJob *locateKeysJob() const = 0;
+    /** Find the best key to use for a mailbox. */
+    virtual KeyForMailboxJob *keyForMailboxJob() const = 0;
 };
 
 /** Obtain a reference to the OpenPGP Protocol.
diff --git a/lang/qt/src/protocol_p.h b/lang/qt/src/protocol_p.h
index 9fcbc8b..afb4f9c 100644
--- a/lang/qt/src/protocol_p.h
+++ b/lang/qt/src/protocol_p.h
@@ -56,6 +56,7 @@
 #include "qgpgmechangeownertrustjob.h"
 #include "qgpgmechangepasswdjob.h"
 #include "qgpgmeadduseridjob.h"
+#include "qgpgmekeyformailboxjob.h"
 
 namespace
 {
@@ -377,6 +378,15 @@ public:
         context->setKeyListMode(GpgME::Extern | GpgME::Local | GpgME::Signatures | GpgME::Validate);
         return new QGpgME::QGpgMEKeyListJob(context);
     }
+
+    QGpgME::KeyForMailboxJob *keyForMailboxJob() const Q_DECL_OVERRIDE
+    {
+        GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
+        if (!context) {
+            return Q_NULLPTR;
+        }
+        return new QGpgME::QGpgMEKeyForMailboxJob(context);
+    }
 };
 
 }
diff --git a/lang/qt/src/qgpgmekeyformailboxjob.cpp b/lang/qt/src/qgpgmekeyformailboxjob.cpp
new file mode 100644
index 0000000..0702a36
--- /dev/null
+++ b/lang/qt/src/qgpgmekeyformailboxjob.cpp
@@ -0,0 +1,136 @@
+/*
+    qgpgmekeyformailboxjob.cpp
+
+    This file is part of qgpgme, the Qt API binding for gpgme
+    Copyright (c) 2016 Intevation GmbH
+
+    QGpgME is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+
+    QGpgME is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of this program with any edition of
+    the Qt library by Trolltech AS, Norway (or with modified versions
+    of Qt that use the same license as Qt), and distribute linked
+    combinations including the two.  You must obey the GNU General
+    Public License in all respects for all of the code used other than
+    Qt.  If you modify this file, you may extend this exception to
+    your version of the file, but you are not obligated to do so.  If
+    you do not wish to do so, delete this exception statement from
+    your version.
+*/
+
+#include "qgpgmekeyformailboxjob.h"
+#include "qgpgmekeylistjob.h"
+
+#include <tuple>
+
+using namespace GpgME;
+using namespace QGpgME;
+
+QGpgMEKeyForMailboxJob::QGpgMEKeyForMailboxJob(Context *context)
+    : mixin_type(context)
+{
+    lateInitialization();
+}
+
+QGpgMEKeyForMailboxJob::~QGpgMEKeyForMailboxJob() {}
+
+static bool keyIsOk(const Key k)
+{
+    return !k.isExpired() && !k.isRevoked() && !k.isInvalid() && !k.isDisabled();
+}
+
+static bool uidIsOk(const UserID uid)
+{
+    return keyIsOk(uid.parent()) && !uid.isRevoked() && !uid.isInvalid();
+}
+
+static bool subkeyIsOk(const Subkey s)
+{
+    return !s.isRevoked() && !s.isInvalid() && !s.isDisabled();
+}
+
+static QGpgMEKeyForMailboxJob::result_type do_work(Context *ctx, const QString &mailbox, bool canEncrypt)
+{
+    /* Do a Keylisting. */
+    ctx->setKeyListMode(GpgME::Extern | GpgME::Local | GpgME::Signatures | GpgME::Validate);
+    std::vector<Key> keys;
+    QGpgMEKeyListJob *keylist = new QGpgMEKeyListJob(ctx);
+
+    KeyListResult result = keylist->exec(QStringList() << mailbox, false, keys);
+
+    if (result.error()) {
+        return std::make_tuple(result, Key(), UserID(), QString(), Error());
+    }
+
+    // This should ideally be decided by GnuPG and this Job changed
+    // to just call the according API in GpgME
+    // See: https://bugs.gnupg.org/gnupg/issue2359
+    Key keyC;
+    UserID uidC;
+    Q_FOREACH (const Key k, keys) {
+        if (canEncrypt && !k.canEncrypt()) {
+            continue;
+        }
+        /* First get the uid that matches the mailbox */
+        Q_FOREACH (const UserID u, k.userIDs()) {
+            if (QString::fromUtf8(u.email()).toLower() == mailbox.toLower()) {
+                if (uidC.isNull()) {
+                    keyC = k;
+                    uidC = u;
+                } else if ((!uidIsOk(uidC) && uidIsOk(u)) || uidC.validity() < u.validity()) {
+                    /* Validity of the new key is better. */
+                    uidC = u;
+                    keyC = k;
+                } else if (uidC.validity() == u.validity() && uidIsOk(u)) {
+                    /* Both are the same check which one is newer. */
+                    time_t oldTime = 0;
+                    Q_FOREACH (const Subkey s, keyC.subkeys()) {
+                        if ((canEncrypt && s.canEncrypt()) && subkeyIsOk(s)) {
+                            oldTime = s.creationTime();
+                        }
+                    }
+                    time_t newTime = 0;
+                    Q_FOREACH (const Subkey s, k.subkeys()) {
+                        if ((canEncrypt && s.canEncrypt()) && subkeyIsOk(s)) {
+                            newTime = s.creationTime();
+                        }
+                    }
+                    if (newTime > oldTime) {
+                        uidC = u;
+                        keyC = k;
+                    }
+                }
+            }
+        }
+    }
+    return std::make_tuple(result, keyC, uidC, QString(), Error());
+}
+
+Error QGpgMEKeyForMailboxJob::start(const QString &mailbox, bool canEncrypt)
+{
+    run(std::bind(&do_work, std::placeholders::_1, mailbox, canEncrypt));
+    return Error();
+}
+
+KeyListResult QGpgMEKeyForMailboxJob::exec(const QString &mailbox, bool canEncrypt, Key &key, UserID &uid)
+{
+    const result_type r = do_work(context(), mailbox, canEncrypt);
+    resultHook(r);
+    key = std::get<1>(r);
+    uid = std::get<2>(r);
+    return std::get<0>(r);
+}
+
+#include "qgpgmekeyformailboxjob.moc"
diff --git a/lang/qt/src/qgpgmekeyformailboxjob.h b/lang/qt/src/qgpgmekeyformailboxjob.h
new file mode 100644
index 0000000..02a16d3
--- /dev/null
+++ b/lang/qt/src/qgpgmekeyformailboxjob.h
@@ -0,0 +1,79 @@
+/*
+    qgpgmekeyformailboxjob.h
+
+    This file is part of libkleopatra, the KDE keymanagement library
+    Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB
+    This file is part of qgpgme, the Qt API binding for gpgme
+    Copyright (c) 2016 Intevation GmbH
+
+    QGpgME is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+
+    QGpgME is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of this program with any edition of
+    the Qt library by Trolltech AS, Norway (or with modified versions
+    of Qt that use the same license as Qt), and distribute linked
+    combinations including the two.  You must obey the GNU General
+    Public License in all respects for all of the code used other than
+    Qt.  If you modify this file, you may extend this exception to
+    your version of the file, but you are not obligated to do so.  If
+    you do not wish to do so, delete this exception statement from
+    your version.
+*/
+
+#ifndef __QGPGME_QGPGMEKEYFORMAILBOXJOB_H__
+#define __QGPGME_QGPGMEKEYFORMAILBOXJOB_H__
+#include "keyformailboxjob.h"
+
+#include "threadedjobmixin.h"
+
+#include <gpgme++/keylistresult.h>
+#include <gpgme++/key.h>
+
+namespace QGpgME
+{
+
+class QGpgMEKeyForMailboxJob
+#ifdef Q_MOC_RUN
+    : public KeyForMailboxJob
+#else
+    : public _detail::ThreadedJobMixin<KeyForMailboxJob, std::tuple<GpgME::KeyListResult, GpgME::Key, GpgME::UserID, QString, GpgME::Error> >
+#endif
+{
+    Q_OBJECT
+#ifdef Q_MOC_RUN
+public Q_SLOTS:
+    void slotFinished();
+#endif
+public:
+    explicit QGpgMEKeyForMailboxJob(GpgME::Context *context);
+    ~QGpgMEKeyForMailboxJob();
+
+    /**
+      Starts the operation. \a mailbox is the mailbox to
+      look for.
+
+      The result is the same as for the LocateKeysJob.
+
+      If \a canEncrypt is true, only keys that have a subkey for encryption
+      usage are returned. Use this if you need to select a
+      key for signing.
+    */
+    GpgME::Error start(const QString &mailbox, bool canEncrypt = true) Q_DECL_OVERRIDE;
+
+    GpgME::KeyListResult exec(const QString &mailbox, bool canEncrypt, GpgME::Key &key, GpgME::UserID &uid) Q_DECL_OVERRIDE;
+};
+
+}
+#endif
diff --git a/lang/qt/tests/Makefile.am b/lang/qt/tests/Makefile.am
index 13495a8..85f6fa6 100644
--- a/lang/qt/tests/Makefile.am
+++ b/lang/qt/tests/Makefile.am
@@ -55,12 +55,14 @@ t_keylocate_SOURCES = t-keylocate.cpp $(support_src)
 t_ownertrust_SOURCES = t-ownertrust.cpp $(support_src)
 t_tofuinfo_SOURCES = t-tofuinfo.cpp $(support_src)
 t_encrypt_SOURCES = t-encrypt.cpp $(support_src)
+run_keyformailboxjob_SOURCES = run-keyformailboxjob.cpp
 
 nodist_t_keylist_SOURCES = $(moc_files)
 
 BUILT_SOURCES = $(moc_files)
 
-noinst_PROGRAMS = t-keylist t-keylocate t-ownertrust t-tofuinfo t-encrypt
+noinst_PROGRAMS = t-keylist t-keylocate t-ownertrust t-tofuinfo t-encrypt \
+    run-keyformailboxjob
 
 CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \
 	gpg-agent.conf pubring.kbx~ S.gpg-agent gpg.conf pubring.gpg~ \
diff --git a/lang/qt/tests/run-keyformailboxjob.cpp b/lang/qt/tests/run-keyformailboxjob.cpp
new file mode 100644
index 0000000..9ac7668
--- /dev/null
+++ b/lang/qt/tests/run-keyformailboxjob.cpp
@@ -0,0 +1,56 @@
+/*
+    run-keyformailbox.cpp
+
+    This file is part of QGpgME's test suite.
+    Copyright (c) 2016 Intevation GmbH
+
+    QGpgME is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License,
+    version 2, as published by the Free Software Foundation.
+
+    QGpgME is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of this program with any edition of
+    the Qt library by Trolltech AS, Norway (or with modified versions
+    of Qt that use the same license as Qt), and distribute linked
+    combinations including the two.  You must obey the GNU General
+    Public License in all respects for all of the code used other than
+    Qt.  If you modify this file, you may extend this exception to
+    your version of the file, but you are not obligated to do so.  If
+    you do not wish to do so, delete this exception statement from
+    your version.
+*/
+
+#include "keyformailboxjob.h"
+#include "keylistjob.h"
+#include "protocol.h"
+
+#include "key.h"
+#include "keylistresult.h"
+
+#include <QDebug>
+
+
+int main(int argc, char **argv)
+{
+    QString mailbox;
+    if (argc == 2) {
+        mailbox = QString::fromLocal8Bit(argv[1]);
+    }
+
+    auto job = QGpgME::openpgp()->keyForMailboxJob();
+    GpgME::Key k;
+    GpgME::UserID uid;
+    job->exec(mailbox, true, k, uid);
+    qDebug() << "UID Name: " << uid.name() << " Mail: " << uid.email() << " id: " << uid.id();
+    qDebug() << "Key fpr: " << k.primaryFingerprint();
+    return 0;
+}

-----------------------------------------------------------------------

Summary of changes:
 lang/qt/src/Makefile.am                            |  17 ++-
 lang/qt/src/abstractimportjob.h                    |   4 +-
 lang/qt/src/cryptoconfig.h                         |   9 +-
 lang/qt/src/defaultkeygenerationjob.cpp            | 123 +++++++++++++++++++
 ...pgmedeletejob.cpp => defaultkeygenerationjob.h} |  67 +++++-----
 lang/qt/src/deletejob.h                            |   3 +-
 lang/qt/src/exportjob.h                            |   3 +-
 lang/qt/src/importfromkeyserverjob.h               |   3 +-
 lang/qt/src/importjob.h                            |   3 +-
 lang/qt/src/job.cpp                                |   3 +
 lang/qt/src/{keylistjob.h => keyformailboxjob.h}   |  74 ++++++-----
 lang/qt/src/keygenerationjob.h                     |   3 +-
 lang/qt/src/keylistjob.h                           |   3 +-
 lang/qt/src/listallkeysjob.h                       |   3 +-
 lang/qt/src/protocol.h                             |   3 +
 lang/qt/src/protocol_p.h                           |  10 ++
 lang/qt/src/qgpgmekeyformailboxjob.cpp             | 136 +++++++++++++++++++++
 ...qgpgmekeylistjob.h => qgpgmekeyformailboxjob.h} |  52 ++++----
 lang/qt/src/refreshkeysjob.h                       |   3 +-
 lang/qt/src/signencryptjob.h                       |   3 +-
 lang/qt/src/specialjob.h                           |   3 +-
 lang/qt/src/verifydetachedjob.h                    |   1 +
 lang/qt/tests/Makefile.am                          |   4 +-
 .../run-keyformailboxjob.cpp}                      |  52 ++++----
 24 files changed, 439 insertions(+), 146 deletions(-)
 create mode 100644 lang/qt/src/defaultkeygenerationjob.cpp
 copy lang/qt/src/{qgpgmedeletejob.cpp => defaultkeygenerationjob.h} (55%)
 copy lang/qt/src/{keylistjob.h => keyformailboxjob.h} (50%)
 create mode 100644 lang/qt/src/qgpgmekeyformailboxjob.cpp
 copy lang/qt/src/{qgpgmekeylistjob.h => qgpgmekeyformailboxjob.h} (63%)
 copy lang/qt/{src/abstractimportjob.h => tests/run-keyformailboxjob.cpp} (59%)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list