diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index 81e07ce6..b696dc66 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -1,438 +1,440 @@ # Makefile.am for GPGMEPP. # Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik # Software engineering by Intevation GmbH # # This file is part of GPGMEPP. # # GPGME-CL 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. # # GPGME-CL 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 Lesser 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., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA if WANT_QT5 lib_LTLIBRARIES = libqgpgme.la endif if WANT_QT6 lib_LTLIBRARIES = libqgpgmeqt6.la endif EXTRA_DIST = QGpgmeConfig.cmake.in.in QGpgmeConfigVersion.cmake.in \ qgpgme_debug.h qgpgme_version.h.in \ QGpgmeConfig-w32.cmake.in.in QGpgmeQt6Config.cmake.in.in \ QGpgmeQt6Config-w32.cmake.in.in QGpgmeQt6ConfigVersion.cmake.in qgpgme_sources = \ cleaner.cpp \ dataprovider.cpp \ debug.cpp \ decryptverifyarchivejob.cpp \ decryptverifyjob.cpp \ encryptarchivejob.cpp \ filelistdataprovider.cpp \ job.cpp multideletejob.cpp qgpgmeadduseridjob.cpp \ qgpgmeaddexistingsubkeyjob.cpp \ qgpgmebackend.cpp qgpgmechangeexpiryjob.cpp qgpgmechangeownertrustjob.cpp \ qgpgmechangepasswdjob.cpp qgpgmedecryptjob.cpp \ qgpgmedecryptverifyarchivejob.cpp \ qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.cpp \ qgpgmeencryptarchivejob.cpp \ qgpgmeencryptjob.cpp qgpgmeexportjob.cpp qgpgmeimportfromkeyserverjob.cpp \ qgpgmeimportjob.cpp qgpgmekeygenerationjob.cpp qgpgmekeylistjob.cpp \ listallkeysjob.cpp qgpgmelistallkeysjob.cpp qgpgmenewcryptoconfig.cpp \ qgpgmereceivekeysjob.cpp \ qgpgmerefreshsmimekeysjob.cpp \ qgpgmerevokekeyjob.cpp \ qgpgmesetprimaryuseridjob.cpp \ qgpgmesignarchivejob.cpp \ qgpgmesignencryptjob.cpp \ qgpgmesignencryptarchivejob.cpp \ qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \ qgpgmeverifyopaquejob.cpp qgpgmewkdlookupjob.cpp threadedjobmixin.cpp \ qgpgmewkdrefreshjob.cpp \ qgpgmekeyformailboxjob.cpp qgpgme_debug.cpp \ qgpgmetofupolicyjob.cpp qgpgmequickjob.cpp \ defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp \ qgpgmegpgcardjob.cpp changeexpiryjob.cpp encryptjob.cpp importjob.cpp \ signarchivejob.cpp \ signencryptjob.cpp \ signencryptarchivejob.cpp \ signjob.cpp \ dn.cpp cryptoconfig.cpp wkdlookupresult.cpp \ util.cpp \ + verifydetachedjob.cpp \ verifyopaquejob.cpp \ wkdrefreshjob.cpp # If you add one here make sure that you also add one in camelcase qgpgme_headers= \ abstractimportjob.h \ addexistingsubkeyjob.h \ adduseridjob.h \ changeexpiryjob.h \ changeownertrustjob.h \ changepasswdjob.h \ dataprovider.h \ debug.h \ decryptjob.h \ decryptverifyarchivejob.h \ decryptverifyjob.h \ downloadjob.h \ encryptarchivejob.h \ encryptjob.h \ exportjob.h \ filelistdataprovider.h \ hierarchicalkeylistjob.h \ job.h \ keyformailboxjob.h \ multideletejob.h \ protocol.h \ qgpgme_export.h \ qgpgmenewcryptoconfig.h \ quickjob.h \ receivekeysjob.h \ revokekeyjob.h \ setprimaryuseridjob.h \ specialjob.h \ signarchivejob.h \ signjob.h \ signkeyjob.h \ signencryptjob.h \ signencryptarchivejob.h \ verifyopaquejob.h \ refreshkeysjob.h \ cryptoconfig.h \ deletejob.h \ importfromkeyserverjob.h \ importjob.h \ keygenerationjob.h \ keylistjob.h \ listallkeysjob.h \ verifydetachedjob.h \ defaultkeygenerationjob.h \ tofupolicyjob.h \ wkdlookupjob.h \ wkdlookupresult.h \ wkdrefreshjob.h \ wkspublishjob.h \ gpgcardjob.h \ dn.h camelcase_headers= \ AddExistingSubkeyJob \ AddUserIDJob \ AbstractImportJob \ ChangeExpiryJob \ ChangeOwnerTrustJob \ ChangePasswdJob \ DataProvider \ Debug \ DecryptJob \ DecryptVerifyArchiveJob \ DecryptVerifyJob \ DN \ DownloadJob \ EncryptArchiveJob \ EncryptJob \ ExportJob \ FileListDataProvider \ HierarchicalKeyKistJob \ Job \ MultiDeleteJob \ Protocol \ QGpgMENewCryptoConfig \ QuickJob \ ReceiveKeysJob \ RevokeKeyJob \ SetPrimaryUserIDJob \ SpecialJob \ SignArchiveJob \ SignJob \ SignKeyJob \ SignEncryptArchiveJob \ SignEncryptJob \ VerifyOpaqueJob \ RefreshKeysJob \ CryptoConfig \ DeleteJob \ ImportFromKeyserverJob \ ImportJob \ KeyGenerationJob \ KeyListJob \ ListAllKeysJob \ VerifyDetachedJob \ KeyForMailboxJob \ DefaultKeyGenerationJob \ WKDLookupJob \ WKDLookupResult \ WKDRefreshJob \ WKSPublishJob \ TofuPolicyJob \ GpgCardJob private_qgpgme_headers = \ changeexpiryjob_p.h \ cleaner.h \ decryptverifyarchivejob_p.h \ decryptverifyjob_p.h \ encryptarchivejob_p.h \ encryptjob_p.h \ importjob_p.h \ listallkeysjob_p.h \ qgpgme_export.h \ protocol_p.h \ job_p.h \ qgpgmeaddexistingsubkeyjob.h \ qgpgmeadduseridjob.h \ qgpgmebackend.h \ qgpgmechangeexpiryjob.h \ qgpgmechangeownertrustjob.h \ qgpgmechangepasswdjob.h \ qgpgmedecryptjob.h \ qgpgmedecryptverifyarchivejob.h \ qgpgmedecryptverifyjob.h \ qgpgmedeletejob.h \ qgpgmedownloadjob.h \ qgpgmeencryptarchivejob.h \ qgpgmeencryptjob.h \ qgpgmeexportjob.h \ qgpgmeimportfromkeyserverjob.h \ qgpgmeimportjob.h \ qgpgmekeygenerationjob.h \ qgpgmekeylistjob.h \ qgpgmelistallkeysjob.h \ qgpgmereceivekeysjob.h \ qgpgmerefreshsmimekeysjob.h \ qgpgmerevokekeyjob.h \ qgpgmesetprimaryuseridjob.h \ qgpgmesignarchivejob.h \ qgpgmesignencryptjob.h \ qgpgmesignencryptarchivejob.h \ qgpgmesignjob.h \ qgpgmesignkeyjob.h \ qgpgmeverifydetachedjob.h \ qgpgmeverifyopaquejob.h \ qgpgmewkdlookupjob.h \ qgpgmewkdrefreshjob.h \ qgpgmekeyformailboxjob.h \ qgpgmewkspublishjob.h \ qgpgmetofupolicyjob.h \ qgpgmegpgcardjob.h \ qgpgmequickjob.h \ signarchivejob_p.h \ signencryptjob_p.h \ signencryptarchivejob_p.h \ signjob_p.h \ threadedjobmixin.h \ util.h \ + verifydetachedjob_p.h \ verifyopaquejob_p.h \ wkdrefreshjob_p.h qgpgme_moc_sources = \ abstractimportjob.moc \ addexistingsubkeyjob.moc \ adduseridjob.moc \ changeexpiryjob.moc \ changeownertrustjob.moc \ changepasswdjob.moc \ cleaner.moc \ decryptjob.moc \ decryptverifyarchivejob.moc \ decryptverifyjob.moc \ deletejob.moc \ downloadjob.moc \ encryptarchivejob.moc \ encryptjob.moc \ exportjob.moc \ hierarchicalkeylistjob.moc \ importfromkeyserverjob.moc \ importjob.moc \ job.moc \ keygenerationjob.moc \ keylistjob.moc \ listallkeysjob.moc \ multideletejob.moc \ qgpgmeaddexistingsubkeyjob.moc \ qgpgmeadduseridjob.moc \ qgpgmechangeexpiryjob.moc \ qgpgmechangeownertrustjob.moc \ qgpgmechangepasswdjob.moc \ qgpgmedecryptjob.moc \ qgpgmedecryptverifyarchivejob.moc \ qgpgmedecryptverifyjob.moc \ qgpgmedeletejob.moc \ qgpgmedownloadjob.moc \ qgpgmeencryptarchivejob.moc \ qgpgmeencryptjob.moc \ qgpgmeexportjob.moc \ qgpgmeimportfromkeyserverjob.moc \ qgpgmeimportjob.moc \ qgpgmekeygenerationjob.moc \ qgpgmekeylistjob.moc \ qgpgmelistallkeysjob.moc \ qgpgmereceivekeysjob.moc \ qgpgmerefreshsmimekeysjob.moc \ qgpgmerevokekeyjob.moc \ qgpgmesetprimaryuseridjob.moc \ qgpgmesignarchivejob.moc \ qgpgmesignencryptjob.moc \ qgpgmesignencryptarchivejob.moc \ qgpgmesignjob.moc \ qgpgmesignkeyjob.moc \ qgpgmeverifydetachedjob.moc \ qgpgmeverifyopaquejob.moc \ qgpgmewkdlookupjob.moc \ qgpgmewkdrefreshjob.moc \ qgpgmewkspublishjob.moc \ tofupolicyjob.moc \ qgpgmetofupolicyjob.moc \ receivekeysjob.moc \ refreshkeysjob.moc \ revokekeyjob.moc \ setprimaryuseridjob.moc \ signarchivejob.moc \ signencryptjob.moc \ signencryptarchivejob.moc \ signjob.moc \ signkeyjob.moc \ specialjob.moc \ verifydetachedjob.moc \ verifyopaquejob.moc \ wkdlookupjob.moc \ wkdrefreshjob.moc \ keyformailboxjob.moc \ wkspublishjob.moc \ qgpgmekeyformailboxjob.moc \ defaultkeygenerationjob.moc \ quickjob.moc \ qgpgmequickjob.moc \ gpgcardjob.moc \ qgpgmegpgcardjob.moc qgpgmeincludedir = $(includedir)/qgpgme qgpgmeinclude_HEADERS = $(qgpgme_headers) camelcaseincludedir = $(includedir)/QGpgME camelcaseinclude_HEADERS = $(camelcase_headers) nodist_qgpgmeinclude_HEADERS = qgpgme_version.h if WANT_QT5 AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPGME_QT5_CFLAGS@ @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \ -DBUILDING_QGPGME -Wsuggest-override \ -Wzero-as-null-pointer-constant libqgpgme_la_SOURCES = $(qgpgme_sources) $(qgpgme_headers) $(private_qgpgme_headers) libqgpgme_la_LIBADD = ../../cpp/src/libgpgmepp.la ../../../src/libgpgme.la \ @LIBASSUAN_LIBS@ @GPG_ERROR_LIBS@ @GPGME_QT5_LIBS@ libqgpgme_la_LDFLAGS = -no-undefined -version-info \ @LIBQGPGME_LT_CURRENT@:@LIBQGPGME_LT_REVISION@:@LIBQGPGME_LT_AGE@ endif if WANT_QT6 AM_CPPFLAGS = -I$(top_srcdir)/lang/cpp/src -I$(top_builddir)/src \ @GPGME_QT6_CFLAGS@ @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \ -DBUILDING_QGPGME -Wsuggest-override \ -Wzero-as-null-pointer-constant libqgpgmeqt6_la_SOURCES = $(qgpgme_sources) $(qgpgme_headers) $(private_qgpgme_headers) libqgpgmeqt6_la_LIBADD = ../../cpp/src/libgpgmepp.la ../../../src/libgpgme.la \ @LIBASSUAN_LIBS@ @GPG_ERROR_LIBS@ @GPGME_QT6_LIBS@ libqgpgmeqt6_la_LDFLAGS = -no-undefined -version-info \ @LIBQGPGME_LT_CURRENT@:@LIBQGPGME_LT_REVISION@:@LIBQGPGME_LT_AGE@ endif if HAVE_MACOS_SYSTEM libsuffix=.dylib else libsuffix=.so endif if WANT_QT5 if HAVE_W32_SYSTEM QGpgmeConfig.cmake: QGpgmeConfig-w32.cmake.in sed -e 's|[@]resolved_bindir@|$(bindir)|g' < "$<" | \ sed -e 's|[@]resolved_libdir@|$(libdir)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ else QGpgmeConfig.cmake: QGpgmeConfig.cmake.in sed -e 's|[@]resolved_libdir@|$(libdir)|g' < "$<" | \ sed -e 's|[@]libsuffix@|$(libsuffix)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ endif endif if WANT_QT6 if HAVE_W32_SYSTEM QGpgmeQt6Config.cmake: QGpgmeQt6Config-w32.cmake.in sed -e 's|[@]resolved_bindir@|$(bindir)|g' < "$<" | \ sed -e 's|[@]resolved_libdir@|$(libdir)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ else QGpgmeQt6Config.cmake: QGpgmeQt6Config.cmake.in sed -e 's|[@]resolved_libdir@|$(libdir)|g' < "$<" | \ sed -e 's|[@]libsuffix@|$(libsuffix)|g' | \ sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ endif endif $(camelcase_headers): Makefile.am echo -n "#include \"qgpgme/" > "$@" echo -n "$@" | tr '[:upper:]' '[:lower:]' >> "$@" echo ".h\"" >> "$@" if WANT_QT5 install-cmake-files: QGpgmeConfig.cmake QGpgmeConfigVersion.cmake -$(INSTALL) -d $(DESTDIR)$(libdir)/cmake/QGpgme $(INSTALL) -m 644 QGpgmeConfig.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfig.cmake $(INSTALL) -m 644 QGpgmeConfigVersion.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfigVersion.cmake uninstall-cmake-files: -rm $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfigVersion.cmake -rm $(DESTDIR)$(libdir)/cmake/QGpgme/QGpgmeConfig.cmake -rmdir $(DESTDIR)$(libdir)/cmake/QGpgme/ endif if WANT_QT6 install-cmake-files: QGpgmeQt6Config.cmake QGpgmeQt6ConfigVersion.cmake -$(INSTALL) -d $(DESTDIR)$(libdir)/cmake/QGpgmeQt6 $(INSTALL) -m 644 QGpgmeQt6Config.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6Config.cmake $(INSTALL) -m 644 QGpgmeQt6ConfigVersion.cmake \ $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6ConfigVersion.cmake uninstall-cmake-files: -rm $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6ConfigVersion.cmake -rm $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/QGpgmeQt6Config.cmake -rmdir $(DESTDIR)$(libdir)/cmake/QGpgmeQt6/ endif install-data-local: install-cmake-files uninstall-local: uninstall-cmake-files BUILT_SOURCES = $(qgpgme_moc_sources) $(camelcase_headers) CLEANFILES = $(qgpgme_moc_sources) $(camelcase_headers) QGpgmeConfig.cmake \ qgpgme_version.h QGpgmeConfig.cmake.in \ QGpgmeConfig-w32.cmake.in QGpgmeConfigVersion.cmake \ QGpgmeQt6Config.cmake.in QGpgmeQt6Config-w32.cmake.in \ QGpgmeQt6Config.cmake QGpgmeQt6ConfigVersion.cmake if WANT_QT5 nodist_libqgpgme_la_SOURCES = $(qgpgme_moc_sources) endif if WANT_QT6 nodist_libqgpgmeqt6_la_SOURCES = $(qgpgme_moc_sources) endif .h.moc: $(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index dbaba195..8150d9a3 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -1,220 +1,217 @@ /* job.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2005 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Copyright (c) 2021 g10 Code GmbH Software engineering by Ingo Klöcker 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. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "job.h" #include "job_p.h" #include "keylistjob.h" #include "listallkeysjob.h" #include "decryptjob.h" #include "signkeyjob.h" -#include "verifydetachedjob.h" #include "keygenerationjob.h" #include "importjob.h" #include "importfromkeyserverjob.h" #include "exportjob.h" #include "changeexpiryjob.h" #include "changeownertrustjob.h" #include "changepasswdjob.h" #include "downloadjob.h" #include "deletejob.h" #include "refreshkeysjob.h" #include "addexistingsubkeyjob.h" #include "adduseridjob.h" #include "specialjob.h" #include "keyformailboxjob.h" #include "wkdlookupjob.h" #include "wkspublishjob.h" #include "tofupolicyjob.h" #include "threadedjobmixin.h" #include "quickjob.h" #include "gpgcardjob.h" #include "receivekeysjob.h" #include "revokekeyjob.h" #include "setprimaryuseridjob.h" #include #include #include #include namespace { typedef std::unordered_map> JobPrivateHash; Q_GLOBAL_STATIC(JobPrivateHash, d_func) } void QGpgME::setJobPrivate(const Job *job, std::unique_ptr d) { auto &ref = d_func()->operator[](job); ref = std::move(d); } const QGpgME::JobPrivate *QGpgME::getJobPrivate(const Job *job) { return d_func()->operator[](job).get(); } QGpgME::JobPrivate *QGpgME::getJobPrivate(Job *job) { return d_func()->operator[](job).get(); } QGpgME::Job::Job(QObject *parent) : QObject(parent) { if (QCoreApplication *app = QCoreApplication::instance()) { connect(app, &QCoreApplication::aboutToQuit, this, &Job::slotCancel); } } QGpgME::Job::~Job() { ::d_func()->erase(this); } QString QGpgME::Job::auditLogAsHtml() const { qDebug() << "QGpgME::Job::auditLogAsHtml() should be reimplemented in Kleo::Job subclasses!"; return QString(); } GpgME::Error QGpgME::Job::auditLogError() const { qDebug() << "QGpgME::Job::auditLogError() should be reimplemented in Kleo::Job subclasses!"; return GpgME::Error::fromCode(GPG_ERR_NOT_IMPLEMENTED); } bool QGpgME::Job::isAuditLogSupported() const { return auditLogError().code() != GPG_ERR_NOT_IMPLEMENTED; } QMap QGpgME::g_context_map; /* static */ GpgME::Context *QGpgME::Job::context(QGpgME::Job *job) { return QGpgME::g_context_map.value (job, nullptr); } GpgME::Error QGpgME::Job::startIt() { auto d = getJobPrivate(this); Q_ASSERT(d && "This Job class has no JobPrivate class"); return d->startIt(); } void QGpgME::Job::startNow() { auto d = getJobPrivate(this); Q_ASSERT(d && "This Job class has no JobPrivate class"); d->startNow(); } #define make_job_subclass_ext(x,y) \ QGpgME::x::x( QObject * parent ) : y( parent ) {} \ QGpgME::x::~x() {} #define make_job_subclass(x) make_job_subclass_ext(x,Job) make_job_subclass(KeyListJob) make_job_subclass(ListAllKeysJob) make_job_subclass(DecryptJob) make_job_subclass(SignKeyJob) -make_job_subclass(VerifyDetachedJob) make_job_subclass(KeyGenerationJob) make_job_subclass(AbstractImportJob) make_job_subclass_ext(ImportJob, AbstractImportJob) make_job_subclass_ext(ImportFromKeyserverJob, AbstractImportJob) make_job_subclass_ext(ReceiveKeysJob, AbstractImportJob) make_job_subclass(ExportJob) make_job_subclass(ChangeExpiryJob) make_job_subclass(ChangeOwnerTrustJob) make_job_subclass(ChangePasswdJob) make_job_subclass(DownloadJob) make_job_subclass(DeleteJob) make_job_subclass(RefreshKeysJob) make_job_subclass(AddExistingSubkeyJob) make_job_subclass(AddUserIDJob) make_job_subclass(SpecialJob) make_job_subclass(KeyForMailboxJob) make_job_subclass(WKDLookupJob) make_job_subclass(WKSPublishJob) make_job_subclass(TofuPolicyJob) make_job_subclass(QuickJob) make_job_subclass(GpgCardJob) make_job_subclass(RevokeKeyJob) make_job_subclass(SetPrimaryUserIDJob) #undef make_job_subclass #include "job.moc" #include "keylistjob.moc" #include "listallkeysjob.moc" #include "decryptjob.moc" #include "signkeyjob.moc" -#include "verifydetachedjob.moc" #include "keygenerationjob.moc" #include "abstractimportjob.moc" #include "importjob.moc" #include "importfromkeyserverjob.moc" #include "exportjob.moc" #include "changeexpiryjob.moc" #include "changeownertrustjob.moc" #include "changepasswdjob.moc" #include "downloadjob.moc" #include "deletejob.moc" #include "refreshkeysjob.moc" #include "addexistingsubkeyjob.moc" #include "adduseridjob.moc" #include "specialjob.moc" #include "keyformailboxjob.moc" #include "wkdlookupjob.moc" #include "wkspublishjob.moc" #include "tofupolicyjob.moc" #include "quickjob.moc" #include "gpgcardjob.moc" #include "receivekeysjob.moc" #include "revokekeyjob.moc" #include "setprimaryuseridjob.moc" diff --git a/lang/qt/src/qgpgmeverifydetachedjob.cpp b/lang/qt/src/qgpgmeverifydetachedjob.cpp index 52d4329b..57b3c368 100644 --- a/lang/qt/src/qgpgmeverifydetachedjob.cpp +++ b/lang/qt/src/qgpgmeverifydetachedjob.cpp @@ -1,126 +1,194 @@ /* qgpgmeverifydetachedjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2007,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by 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. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "qgpgmeverifydetachedjob.h" #include "dataprovider.h" +#include "util.h" +#include "verifydetachedjob_p.h" -#include "context.h" -#include "verificationresult.h" -#include "data.h" +#include + +#include +#include +#include #include using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMEVerifyDetachedJobPrivate : public VerifyDetachedJobPrivate +{ + QGpgMEVerifyDetachedJob *q = nullptr; + +public: + QGpgMEVerifyDetachedJobPrivate(QGpgMEVerifyDetachedJob *qq) + : q{qq} + { + } + + ~QGpgMEVerifyDetachedJobPrivate() override = default; + +private: + GpgME::Error startIt() override; + + void startNow() override + { + q->run(); + } +}; + +} + QGpgMEVerifyDetachedJob::QGpgMEVerifyDetachedJob(Context *context) : mixin_type(context) { + setJobPrivate(this, std::unique_ptr{new QGpgMEVerifyDetachedJobPrivate{this}}); lateInitialization(); } QGpgMEVerifyDetachedJob::~QGpgMEVerifyDetachedJob() {} static QGpgMEVerifyDetachedJob::result_type verify_detached(Context *ctx, QThread *thread, const std::weak_ptr &signature_, const std::weak_ptr &signedData_) { const std::shared_ptr signature = signature_.lock(); const std::shared_ptr signedData = signedData_.lock(); const _detail::ToThreadMover sgMover(signature, thread); const _detail::ToThreadMover sdMover(signedData, thread); QGpgME::QIODeviceDataProvider sigDP(signature); Data sig(&sigDP); QGpgME::QIODeviceDataProvider dataDP(signedData); Data data(&dataDP); if (!signedData->isSequential()) { data.setSizeHint(signedData->size()); } const VerificationResult res = ctx->verifyDetachedSignature(sig, data); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } static QGpgMEVerifyDetachedJob::result_type verify_detached_qba(Context *ctx, const QByteArray &signature, const QByteArray &signedData) { QGpgME::QByteArrayDataProvider sigDP(signature); Data sig(&sigDP); QGpgME::QByteArrayDataProvider dataDP(signedData); Data data(&dataDP); const VerificationResult res = ctx->verifyDetachedSignature(sig, data); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } +static QGpgMEVerifyDetachedJob::result_type verify_from_filename(Context *ctx, + const QString &signatureFilePath, + const QString &signedFilePath) +{ + Data signatureData; +#ifdef Q_OS_WIN + signatureData.setFileName(signatureFilePath().toUtf8().constData()); +#else + signatureData.setFileName(QFile::encodeName(signatureFilePath).constData()); +#endif + + Data signedData; +#ifdef Q_OS_WIN + signedData.setFileName(signedFilePath().toUtf8().constData()); +#else + signedData.setFileName(QFile::encodeName(signedFilePath).constData()); +#endif + + const auto verificationResult = ctx->verifyDetachedSignature(signatureData, signedData); + + Error ae; + const QString log = _detail::audit_log_as_html(ctx, ae); + return std::make_tuple(verificationResult, log, ae); +} + Error QGpgMEVerifyDetachedJob::start(const QByteArray &signature, const QByteArray &signedData) { run(std::bind(&verify_detached_qba, std::placeholders::_1, signature, signedData)); return Error(); } void QGpgMEVerifyDetachedJob::start(const std::shared_ptr &signature, const std::shared_ptr &signedData) { run(std::bind(&verify_detached, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), signature, signedData); } GpgME::VerificationResult QGpgME::QGpgMEVerifyDetachedJob::exec(const QByteArray &signature, const QByteArray &signedData) { const result_type r = verify_detached_qba(context(), signature, signedData); resultHook(r); return mResult; } -//PENDING(marc) implement showErrorDialog() - void QGpgME::QGpgMEVerifyDetachedJob::resultHook(const result_type &tuple) { mResult = std::get<0>(tuple); } + +GpgME::Error QGpgMEVerifyDetachedJobPrivate::startIt() +{ + if (m_signatureFilePath.isEmpty() || m_signedFilePath.isEmpty()) { + return Error::fromCode(GPG_ERR_INV_VALUE); + } + + q->run([=](Context *ctx) { + return verify_from_filename(ctx, m_signatureFilePath, m_signedFilePath); + }); + + return {}; +} + #include "qgpgmeverifydetachedjob.moc" diff --git a/lang/qt/src/verifydetachedjob.cpp b/lang/qt/src/verifydetachedjob.cpp new file mode 100644 index 00000000..11e630c1 --- /dev/null +++ b/lang/qt/src/verifydetachedjob.cpp @@ -0,0 +1,74 @@ +/* + verifydetachedjob.cpp + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2024 g10 Code GmbH + Software engineering by Ingo Klöcker + + 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. +*/ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include "verifydetachedjob.h" +#include "verifydetachedjob_p.h" + +using namespace QGpgME; + +VerifyDetachedJob::VerifyDetachedJob(QObject *parent) + : Job{parent} +{ +} + +VerifyDetachedJob::~VerifyDetachedJob() = default; + +void VerifyDetachedJob::setSignatureFile(const QString &path) +{ + auto d = jobPrivate(this); + d->m_signatureFilePath = path; +} + +QString VerifyDetachedJob::signatureFile() const +{ + auto d = jobPrivate(this); + return d->m_signatureFilePath; +} + +void VerifyDetachedJob::setSignedFile(const QString &path) +{ + auto d = jobPrivate(this); + d->m_signedFilePath = path; +} + +QString VerifyDetachedJob::signedFile() const +{ + auto d = jobPrivate(this); + return d->m_signedFilePath; +} + +#include "verifydetachedjob.moc" diff --git a/lang/qt/src/verifydetachedjob.h b/lang/qt/src/verifydetachedjob.h index 12fdfbb0..c8c516bf 100644 --- a/lang/qt/src/verifydetachedjob.h +++ b/lang/qt/src/verifydetachedjob.h @@ -1,95 +1,116 @@ /* verifydetachedjob.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004, 2007 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by 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_VERIFYDETACHEDJOB_H__ #define __KLEO_VERIFYDETACHEDJOB_H__ #include "job.h" -#include "qgpgme_export.h" #include class QByteArray; class QIODevice; namespace GpgME { class Error; class VerificationResult; } namespace QGpgME { /** @short An abstract base class for asynchronous verification of detached signatures To use a VerifyDetachedJob, first obtain an instance from the CryptoBackend implementation, connect the progress() and result() signals to suitable slots and then start the verification with a call to start(). This call might fail, in which case the VerifyDetachedJob instance will have scheduled it's own destruction with a call to QObject::deleteLater(). + Alternatively, the job can be started with startIt() after setting + the input files. If the job is started this way then the backend reads the + input directly from the specified input files. This direct IO mode is + currently only supported for OpenPGP. Note that startIt() does not schedule + the job's destruction if starting the job failed. + After result() is emitted, the VerifyDetachedJob will schedule it's own destruction by calling QObject::deleteLater(). */ class QGPGME_EXPORT VerifyDetachedJob : public Job { Q_OBJECT protected: explicit VerifyDetachedJob(QObject *parent); public: - ~VerifyDetachedJob(); + ~VerifyDetachedJob() override; + + /** + * Sets the path of the file containing the signature to verify. + * + * Used if the job is started with startIt(). + */ + void setSignatureFile(const QString &path); + QString signatureFile() const; + + /** + * Sets the path of the file containing the signed data to verify. + * + * Used if the job is started with startIt(). + */ + void setSignedFile(const QString &path); + QString signedFile() const; /** Starts the verification operation. \a signature contains the signature data, while \a signedData contains the data over which the signature was made. */ virtual GpgME::Error start(const QByteArray &signature, const QByteArray &signedData) = 0; virtual void start(const std::shared_ptr &signature, const std::shared_ptr &signedData) = 0; virtual GpgME::VerificationResult exec(const QByteArray &signature, const QByteArray &signedData) = 0; Q_SIGNALS: void result(const GpgME::VerificationResult &result, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error()); }; } #endif // __KLEO_VERIFYDETACHEDJOB_H__ diff --git a/lang/qt/src/verifydetachedjob_p.h b/lang/qt/src/verifydetachedjob_p.h new file mode 100644 index 00000000..1fedc8fb --- /dev/null +++ b/lang/qt/src/verifydetachedjob_p.h @@ -0,0 +1,50 @@ +/* + verifydetachedjob_p.h + + This file is part of qgpgme, the Qt API binding for gpgme + Copyright (c) 2024 g10 Code GmbH + Software engineering by Ingo Klöcker + + 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_VERIFYDETACHEDJOB_P_H__ +#define __QGPGME_VERIFYDETACHEDJOB_P_H__ + +#include "job_p.h" + +namespace QGpgME +{ + +struct VerifyDetachedJobPrivate : public JobPrivate +{ + QString m_signatureFilePath; + QString m_signedFilePath; +}; + +} + +#endif // __QGPGME_VERIFYDETACHEDJOB_P_H__ diff --git a/lang/qt/tests/Makefile.am b/lang/qt/tests/Makefile.am index e3dec517..3e579303 100644 --- a/lang/qt/tests/Makefile.am +++ b/lang/qt/tests/Makefile.am @@ -1,156 +1,158 @@ # Makefile.am - Makefile for GPGME Qt tests. # Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik # Software engineering by Intevation GmbH # # This file is part of GPGME. # # GPGME is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # GPGME 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 Lesser General # Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, see . ## Process this file with automake to produce Makefile.in GPG = gpg GNUPGHOME=$(abs_builddir) TESTS_ENVIRONMENT = GNUPGHOME=$(GNUPGHOME) EXTRA_DIST = initial.test final.test the_tests = \ t-addexistingsubkey \ t-decryptverify \ t-keylist t-keylocate t-ownertrust t-tofuinfo \ t-encrypt t-verify t-various t-config t-remarks t-trustsignatures \ t-changeexpiryjob t-wkdlookup t-import t-revokekey t-setprimaryuserid TESTS = initial.test $(the_tests) final.test moc_files = \ t-addexistingsubkey.moc \ t-decryptverify.moc \ t-keylist.moc t-keylocate.moc t-ownertrust.moc t-tofuinfo.moc \ t-encrypt.moc t-support.hmoc t-wkspublish.moc t-verify.moc \ t-various.moc t-config.moc t-remarks.moc t-trustsignatures.moc \ t-changeexpiryjob.moc t-wkdlookup.moc t-import.moc t-revokekey.moc \ t-setprimaryuserid.moc AM_LDFLAGS = -no-install if WANT_QT5 LDADD = ../../cpp/src/libgpgmepp.la ../src/libqgpgme.la \ ../../../src/libgpgme.la @GPGME_QT5_LIBS@ @GPG_ERROR_LIBS@ \ @GPGME_QT5TEST_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ -lstdc++ AM_CPPFLAGS = -I$(top_srcdir)/lang/qt/src -I$(top_srcdir)/lang/cpp/src \ -I$(top_builddir)/src \ @GPG_ERROR_CFLAGS@ @GPGME_QT5_CFLAGS@ @GPG_ERROR_CFLAGS@ \ @LIBASSUAN_CFLAGS@ @GPGME_QT5TEST_CFLAGS@ -DBUILDING_QGPGME \ -DTOP_SRCDIR="$(top_srcdir)" endif if WANT_QT6 LDADD = ../../cpp/src/libgpgmepp.la ../src/libqgpgmeqt6.la \ ../../../src/libgpgme.la @GPGME_QT6_LIBS@ @GPG_ERROR_LIBS@ \ @GPGME_QT6TEST_LIBS@ @LDADD_FOR_TESTS_KLUDGE@ -lstdc++ AM_CPPFLAGS = -I$(top_srcdir)/lang/qt/src -I$(top_srcdir)/lang/cpp/src \ -I$(top_builddir)/src \ @GPG_ERROR_CFLAGS@ @GPGME_QT6_CFLAGS@ @GPG_ERROR_CFLAGS@ \ @LIBASSUAN_CFLAGS@ @GPGME_QT6TEST_CFLAGS@ -DBUILDING_QGPGME \ -DTOP_SRCDIR="$(top_srcdir)" endif support_src = t-support.h t-support.cpp t_addexistingsubkey_SOURCES = t-addexistingsubkey.cpp $(support_src) t_decryptverify_SOURCES = t-decryptverify.cpp $(support_src) t_keylist_SOURCES = t-keylist.cpp $(support_src) 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) t_wkspublish_SOURCES = t-wkspublish.cpp $(support_src) t_verify_SOURCES = t-verify.cpp $(support_src) t_various_SOURCES = t-various.cpp $(support_src) t_config_SOURCES = t-config.cpp $(support_src) t_remarks_SOURCES = t-remarks.cpp $(support_src) t_trustsignatures_SOURCES = t-trustsignatures.cpp $(support_src) t_changeexpiryjob_SOURCES = t-changeexpiryjob.cpp $(support_src) t_wkdlookup_SOURCES = t-wkdlookup.cpp $(support_src) t_import_SOURCES = t-import.cpp $(support_src) t_revokekey_SOURCES = t-revokekey.cpp $(support_src) t_setprimaryuserid_SOURCES = t-setprimaryuserid.cpp $(support_src) run_decryptverifyjob_SOURCES = run-decryptverifyjob.cpp run_decryptverifyarchivejob_SOURCES = run-decryptverifyarchivejob.cpp run_encryptarchivejob_SOURCES = run-encryptarchivejob.cpp run_encryptjob_SOURCES = run-encryptjob.cpp run_exportjob_SOURCES = run-exportjob.cpp run_importjob_SOURCES = run-importjob.cpp run_keyformailboxjob_SOURCES = run-keyformailboxjob.cpp run_receivekeysjob_SOURCES = run-receivekeysjob.cpp run_refreshkeysjob_SOURCES = run-refreshkeysjob.cpp run_signarchivejob_SOURCES = run-signarchivejob.cpp run_signjob_SOURCES = run-signjob.cpp +run_verifydetachedjob_SOURCES = run-verifydetachedjob.cpp run_verifyopaquejob_SOURCES = run-verifyopaquejob.cpp run_wkdrefreshjob_SOURCES = run-wkdrefreshjob.cpp nodist_t_keylist_SOURCES = $(moc_files) BUILT_SOURCES = $(moc_files) pubring-stamp noinst_PROGRAMS = \ t-addexistingsubkey \ t-decryptverify \ t-keylist t-keylocate t-ownertrust t-tofuinfo t-encrypt \ run-keyformailboxjob t-wkspublish t-verify t-various t-config t-remarks \ t-trustsignatures t-changeexpiryjob t-wkdlookup t-import t-revokekey \ t-setprimaryuserid \ run-decryptverifyarchivejob \ run-decryptverifyjob \ run-encryptarchivejob \ run-encryptjob \ run-importjob run-exportjob run-receivekeysjob run-refreshkeysjob \ run-signarchivejob \ run-signjob \ + run-verifydetachedjob \ run-verifyopaquejob \ run-wkdrefreshjob CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \ gpg-agent.conf pubring.kbx~ S.gpg-agent gpg.conf pubring.gpg~ \ random_seed S.gpg-agent .gpg-v21-migrated pubring-stamp $(moc_files) \ gpg.conf tofu.db reader_0.status reader_1.status clean-local: -$(TESTS_ENVIRONMENT) $(top_srcdir)/tests/start-stop-agent --stop -rm -fR private-keys-v1.d crls.d pubring-stamp: $(top_srcdir)/tests/gpg/pubdemo.asc \ $(top_srcdir)/tests/gpg/secdemo.asc -$(TESTS_ENVIRONMENT) gpgconf --kill all echo "ignore-invalid-option allow-loopback-pinentry" > $(abs_builddir)/gpg-agent.conf echo "allow-loopback-pinentry" >> gpg-agent.conf echo "ignore-invalid-option pinentry-mode" > gpg.conf echo "pinentry-mode loopback" >> gpg.conf $(TESTS_ENVIRONMENT) $(GPG) --no-permission-warning \ --import $(top_srcdir)/tests/gpg/pubdemo.asc $(TESTS_ENVIRONMENT) $(GPG) --no-permission-warning \ --passphrase "abc" \ --import $(top_srcdir)/tests/gpg/secdemo.asc -$(TESTS_ENVIRONMENT) gpgconf --kill all touch pubring-stamp .cpp.moc: $(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ .h.hmoc: $(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@ diff --git a/lang/qt/tests/run-verifydetachedjob.cpp b/lang/qt/tests/run-verifydetachedjob.cpp new file mode 100644 index 00000000..6ee21109 --- /dev/null +++ b/lang/qt/tests/run-verifydetachedjob.cpp @@ -0,0 +1,121 @@ +/* + run-verifydetachedjob.cpp + + This file is part of QGpgME's test suite. + Copyright (c) 2024 by g10 Code GmbH + Software engineering by Ingo Klöcker + + 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. +*/ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +using namespace GpgME; + +std::ostream &operator<<(std::ostream &os, const QString &s) +{ + return os << s.toLocal8Bit().constData(); +} + +struct CommandLineOptions { + QString signatureFile; + QString signedFile; +}; + +CommandLineOptions parseCommandLine(const QStringList &arguments) +{ + CommandLineOptions options; + + QCommandLineParser parser; + parser.setApplicationDescription("Test program for VerifyDetachedJob"); + parser.addHelpOption(); + parser.addPositionalArgument("signature", "Detached SIGNATURE to verify", "SIGNATURE"); + parser.addPositionalArgument("signed file", "FILE containing the signed data", "FILE"); + + parser.process(arguments); + + const auto args = parser.positionalArguments(); + if (args.size() != 2) { + parser.showHelp(1); + } + + options.signatureFile = args[0]; + options.signedFile = args[1]; + + return options; +} + +int main(int argc, char **argv) +{ + GpgME::initializeLibrary(); + + QCoreApplication app{argc, argv}; + app.setApplicationName("run-verifydetachedjob"); + + const auto options = parseCommandLine(app.arguments()); + + auto job = QGpgME::openpgp()->verifyDetachedJob(); + if (!job) { + std::cerr << "Error: Could not create job" << std::endl; + return 1; + } + QObject::connect(job, + &QGpgME::VerifyDetachedJob::result, + &app, + [](const GpgME::VerificationResult &verificationResult, + const QString &auditLog, + const GpgME::Error &) { + std::cerr << "Diagnostics: " << auditLog << std::endl; + std::cerr << "Verification Result: " << verificationResult << std::endl; + qApp->quit(); + }); + + std::shared_ptr input; + GpgME::Error err; + job->setSignatureFile(options.signatureFile); + job->setSignedFile(options.signedFile); + err = job->startIt(); + if (err) { + std::cerr << "Error: Starting the job failed: " << err.asString() << std::endl; + return 1; + } + + return app.exec(); +}