diff --git a/lang/qt/src/Makefile.am b/lang/qt/src/Makefile.am index e5358b49..510802a8 100644 --- a/lang/qt/src/Makefile.am +++ b/lang/qt/src/Makefile.am @@ -1,381 +1,386 @@ # 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 = \ dataprovider.cpp \ debug.cpp \ job.cpp multideletejob.cpp qgpgmeadduseridjob.cpp \ qgpgmeaddexistingsubkeyjob.cpp \ qgpgmebackend.cpp qgpgmechangeexpiryjob.cpp qgpgmechangeownertrustjob.cpp \ qgpgmechangepasswdjob.cpp qgpgmedecryptjob.cpp \ qgpgmedecryptverifyjob.cpp qgpgmedeletejob.cpp qgpgmedownloadjob.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 \ qgpgmesignencryptjob.cpp \ qgpgmesignjob.cpp qgpgmesignkeyjob.cpp qgpgmeverifydetachedjob.cpp \ qgpgmeverifyopaquejob.cpp qgpgmewkdlookupjob.cpp threadedjobmixin.cpp \ qgpgmekeyformailboxjob.cpp qgpgme_debug.cpp \ qgpgmetofupolicyjob.cpp qgpgmequickjob.cpp \ defaultkeygenerationjob.cpp qgpgmewkspublishjob.cpp \ qgpgmegpgcardjob.cpp changeexpiryjob.cpp encryptjob.cpp importjob.cpp \ signencryptjob.cpp \ dn.cpp cryptoconfig.cpp wkdlookupresult.cpp \ util.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 \ decryptverifyjob.h \ downloadjob.h \ encryptjob.h \ exportjob.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 \ signjob.h \ signkeyjob.h \ signencryptjob.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 \ wkspublishjob.h \ gpgcardjob.h \ dn.h camelcase_headers= \ AddExistingSubkeyJob \ AddUserIDJob \ AbstractImportJob \ ChangeExpiryJob \ ChangeOwnerTrustJob \ ChangePasswdJob \ DataProvider \ Debug \ DecryptJob \ DecryptVerifyJob \ DN \ DownloadJob \ EncryptJob \ ExportJob \ HierarchicalKeyKistJob \ Job \ MultiDeleteJob \ Protocol \ QGpgMENewCryptoConfig \ QuickJob \ ReceiveKeysJob \ RevokeKeyJob \ SetPrimaryUserIDJob \ SpecialJob \ SignJob \ SignKeyJob \ SignEncryptJob \ VerifyOpaqueJob \ RefreshKeysJob \ CryptoConfig \ DeleteJob \ ImportFromKeyserverJob \ ImportJob \ KeyGenerationJob \ KeyListJob \ ListAllKeysJob \ VerifyDetachedJob \ KeyForMailboxJob \ DefaultKeyGenerationJob \ WKDLookupJob \ WKDLookupResult \ WKSPublishJob \ TofuPolicyJob \ GpgCardJob private_qgpgme_headers = \ + changeexpiryjob_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 \ qgpgmedecryptverifyjob.h \ qgpgmedeletejob.h \ qgpgmedownloadjob.h \ qgpgmeencryptjob.h \ qgpgmeexportjob.h \ qgpgmeimportfromkeyserverjob.h \ qgpgmeimportjob.h \ qgpgmekeygenerationjob.h \ qgpgmekeylistjob.h \ qgpgmelistallkeysjob.h \ qgpgmereceivekeysjob.h \ qgpgmerefreshsmimekeysjob.h \ qgpgmerevokekeyjob.h \ qgpgmesetprimaryuseridjob.h \ qgpgmesignencryptjob.h \ qgpgmesignjob.h \ qgpgmesignkeyjob.h \ qgpgmeverifydetachedjob.h \ qgpgmeverifyopaquejob.h \ qgpgmewkdlookupjob.h \ qgpgmekeyformailboxjob.h \ qgpgmewkspublishjob.h \ qgpgmetofupolicyjob.h \ qgpgmegpgcardjob.h \ qgpgmequickjob.h \ + signencryptjob_p.h \ threadedjobmixin.h \ util.h qgpgme_moc_sources = \ abstractimportjob.moc \ addexistingsubkeyjob.moc \ adduseridjob.moc \ changeexpiryjob.moc \ changeownertrustjob.moc \ changepasswdjob.moc \ decryptjob.moc \ decryptverifyjob.moc \ deletejob.moc \ downloadjob.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 \ qgpgmedecryptverifyjob.moc \ qgpgmedeletejob.moc \ qgpgmedownloadjob.moc \ qgpgmeencryptjob.moc \ qgpgmeexportjob.moc \ qgpgmeimportfromkeyserverjob.moc \ qgpgmeimportjob.moc \ qgpgmekeygenerationjob.moc \ qgpgmekeylistjob.moc \ qgpgmelistallkeysjob.moc \ qgpgmereceivekeysjob.moc \ qgpgmerefreshsmimekeysjob.moc \ qgpgmerevokekeyjob.moc \ qgpgmesetprimaryuseridjob.moc \ qgpgmesignencryptjob.moc \ qgpgmesignjob.moc \ qgpgmesignkeyjob.moc \ qgpgmeverifydetachedjob.moc \ qgpgmeverifyopaquejob.moc \ qgpgmewkdlookupjob.moc \ qgpgmewkspublishjob.moc \ tofupolicyjob.moc \ qgpgmetofupolicyjob.moc \ receivekeysjob.moc \ refreshkeysjob.moc \ revokekeyjob.moc \ setprimaryuseridjob.moc \ signencryptjob.moc \ signjob.moc \ signkeyjob.moc \ specialjob.moc \ verifydetachedjob.moc \ verifyopaquejob.moc \ wkdlookupjob.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/changeexpiryjob.cpp b/lang/qt/src/changeexpiryjob.cpp index 49f68cc1..96d02167 100644 --- a/lang/qt/src/changeexpiryjob.cpp +++ b/lang/qt/src/changeexpiryjob.cpp @@ -1,76 +1,62 @@ /* changeexpiryjob.cpp This file is part of qgpgme, the Qt API binding for gpgme 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 "changeexpiryjob.h" -#include "job_p.h" +#include "changeexpiryjob_p.h" #include using namespace GpgME; using namespace QGpgME; -namespace -{ -struct ChangeExpiryJobPrivate : public JobPrivate -{ - ChangeExpiryJobPrivate() - { - } - - ~ChangeExpiryJobPrivate() override = default; - - ChangeExpiryJob::Options m_options = ChangeExpiryJob::Default; -}; -} - void ChangeExpiryJob::setOptions(ChangeExpiryJob::Options options) { auto d = jobPrivate(this); d->m_options = options; } ChangeExpiryJob::Options ChangeExpiryJob::options() const { auto d = jobPrivate(this); return d->m_options; } /* For ABI compat not pure virtual. */ Error ChangeExpiryJob::start(const Key &, const QDateTime &, const std::vector &) { return {}; } diff --git a/lang/qt/src/encryptjob.cpp b/lang/qt/src/changeexpiryjob_p.h similarity index 75% copy from lang/qt/src/encryptjob.cpp copy to lang/qt/src/changeexpiryjob_p.h index 7533bd9d..c6c91c25 100644 --- a/lang/qt/src/encryptjob.cpp +++ b/lang/qt/src/changeexpiryjob_p.h @@ -1,61 +1,51 @@ /* - encryptjob.cpp + changeexpiryjob_p.h This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2021,2023 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 +#ifndef __QGPGME_CHANGEEXPIRYJOB_P_H__ +#define __QGPGME_CHANGEEXPIRYJOB_P_H__ -#include "encryptjob.h" #include "job_p.h" -using namespace QGpgME; +#include "changeexpiryjob.h" -namespace +namespace QGpgME { -struct EncryptJobPrivate : public JobPrivate + +struct ChangeExpiryJobPrivate : public JobPrivate { - QString m_fileName; + ChangeExpiryJob::Options m_options = ChangeExpiryJob::Default; }; -} -void EncryptJob::setFileName(const QString &fileName) -{ - auto d = jobPrivate(this); - d->m_fileName = fileName; } -QString EncryptJob::fileName() const -{ - auto d = jobPrivate(this); - return d->m_fileName; -} +#endif // __QGPGME_CHANGEEXPIRYJOB_P_H__ diff --git a/lang/qt/src/encryptjob.cpp b/lang/qt/src/encryptjob.cpp index 7533bd9d..7b9f0f2b 100644 --- a/lang/qt/src/encryptjob.cpp +++ b/lang/qt/src/encryptjob.cpp @@ -1,61 +1,53 @@ /* encryptjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2022 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 "encryptjob.h" -#include "job_p.h" +#include "encryptjob_p.h" using namespace QGpgME; -namespace -{ -struct EncryptJobPrivate : public JobPrivate -{ - QString m_fileName; -}; -} - void EncryptJob::setFileName(const QString &fileName) { auto d = jobPrivate(this); d->m_fileName = fileName; } QString EncryptJob::fileName() const { auto d = jobPrivate(this); return d->m_fileName; } diff --git a/lang/qt/src/encryptjob.cpp b/lang/qt/src/encryptjob_p.h similarity index 79% copy from lang/qt/src/encryptjob.cpp copy to lang/qt/src/encryptjob_p.h index 7533bd9d..4a93f5b3 100644 --- a/lang/qt/src/encryptjob.cpp +++ b/lang/qt/src/encryptjob_p.h @@ -1,61 +1,49 @@ /* - encryptjob.cpp + encryptjob_p.h This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2022,2023 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 +#ifndef __QGPGME_ENCRYPTJOB_P_H__ +#define __QGPGME_ENCRYPTJOB_P_H__ -#include "encryptjob.h" #include "job_p.h" -using namespace QGpgME; - -namespace +namespace QGpgME { + struct EncryptJobPrivate : public JobPrivate { QString m_fileName; }; -} -void EncryptJob::setFileName(const QString &fileName) -{ - auto d = jobPrivate(this); - d->m_fileName = fileName; } -QString EncryptJob::fileName() const -{ - auto d = jobPrivate(this); - return d->m_fileName; -} +#endif // __QGPGME_ENCRYPTJOB_P_H__ diff --git a/lang/qt/src/importjob.cpp b/lang/qt/src/importjob.cpp index 4f40d9b1..ee5318a4 100644 --- a/lang/qt/src/importjob.cpp +++ b/lang/qt/src/importjob.cpp @@ -1,91 +1,75 @@ /* importjob.cpp This file is part of qgpgme, the Qt API binding for gpgme 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 "importjob.h" -#include "job_p.h" +#include "importjob_p.h" #include using namespace GpgME; using namespace QGpgME; -namespace -{ -struct ImportJobPrivate : public JobPrivate -{ - ImportJobPrivate() - { - } - - ~ImportJobPrivate() override = default; - - QString m_importFilter; - Key::Origin m_keyOrigin = Key::OriginUnknown; - QString m_keyOriginUrl; -}; -} - void QGpgME::ImportJob::setImportFilter(const QString &filter) { const auto d = jobPrivate(this); d->m_importFilter = filter; } QString QGpgME::ImportJob::importFilter() const { const auto d = jobPrivate(this); return d->m_importFilter; } void ImportJob::setKeyOrigin(GpgME::Key::Origin origin, const QString &url) { const auto d = jobPrivate(this); d->m_keyOrigin = origin; d->m_keyOriginUrl = url; } GpgME::Key::Origin ImportJob::keyOrigin() const { const auto d = jobPrivate(this); return d->m_keyOrigin; } QString ImportJob::keyOriginUrl() const { const auto d = jobPrivate(this); return d->m_keyOriginUrl; } diff --git a/lang/qt/src/encryptjob.cpp b/lang/qt/src/importjob_p.h similarity index 75% copy from lang/qt/src/encryptjob.cpp copy to lang/qt/src/importjob_p.h index 7533bd9d..9f0a35ae 100644 --- a/lang/qt/src/encryptjob.cpp +++ b/lang/qt/src/importjob_p.h @@ -1,61 +1,53 @@ /* - encryptjob.cpp + importjob_p.h This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2021,2023 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 +#ifndef __QGPGME_IMPORTJOB_P_H__ +#define __QGPGME_IMPORTJOB_P_H__ -#include "encryptjob.h" #include "job_p.h" -using namespace QGpgME; +#include -namespace +namespace QGpgME { -struct EncryptJobPrivate : public JobPrivate + +struct ImportJobPrivate : public JobPrivate { - QString m_fileName; + QString m_importFilter; + GpgME::Key::Origin m_keyOrigin = GpgME::Key::OriginUnknown; + QString m_keyOriginUrl; }; -} -void EncryptJob::setFileName(const QString &fileName) -{ - auto d = jobPrivate(this); - d->m_fileName = fileName; } -QString EncryptJob::fileName() const -{ - auto d = jobPrivate(this); - return d->m_fileName; -} +#endif // __QGPGME_IMPORTJOB_P_H__ diff --git a/lang/qt/src/job_p.h b/lang/qt/src/job_p.h index 3bce4cff..5a77b75b 100644 --- a/lang/qt/src/job_p.h +++ b/lang/qt/src/job_p.h @@ -1,70 +1,65 @@ /* job_p.h This file is part of qgpgme, the Qt API binding for gpgme 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. */ #ifndef __QGPGME_JOB_P_H__ #define __QGPGME_JOB_P_H__ #include "job.h" #include namespace QGpgME { // Base class for pimpl classes for Job subclasses class JobPrivate { public: virtual ~JobPrivate() {} }; // Setter and getters for the externally stored pimpl instances of jobs // BCI: Add a real d-pointer to Job void setJobPrivate(const Job *job, std::unique_ptr d); JobPrivate *getJobPrivate(const Job *job); template static T *jobPrivate(const Job *job) { auto d = getJobPrivate(job); - if (!d) { - std::unique_ptr ref{new T}; - d = ref.get(); - setJobPrivate(job, std::move(ref)); - } return dynamic_cast(d); } } #endif // __QGPGME_JOB_P_H__ diff --git a/lang/qt/src/listallkeysjob.cpp b/lang/qt/src/listallkeysjob.cpp index f72a45d1..1dce75bf 100644 --- a/lang/qt/src/listallkeysjob.cpp +++ b/lang/qt/src/listallkeysjob.cpp @@ -1,65 +1,53 @@ /* listallkeysjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2022 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 "listallkeysjob.h" -#include "job_p.h" +#include "listallkeysjob_p.h" using namespace QGpgME; -namespace -{ -struct ListAllKeysJobPrivate : public JobPrivate -{ - ListAllKeysJobPrivate() = default; - - ~ListAllKeysJobPrivate() override = default; - - ListAllKeysJob::Options m_options = ListAllKeysJob::Default; -}; -} - void ListAllKeysJob::setOptions(ListAllKeysJob::Options options) { auto d = jobPrivate(this); d->m_options = options; } ListAllKeysJob::Options ListAllKeysJob::options() const { auto d = jobPrivate(this); return d->m_options; } diff --git a/lang/qt/src/listallkeysjob.cpp b/lang/qt/src/listallkeysjob_p.h similarity index 76% copy from lang/qt/src/listallkeysjob.cpp copy to lang/qt/src/listallkeysjob_p.h index f72a45d1..582f028b 100644 --- a/lang/qt/src/listallkeysjob.cpp +++ b/lang/qt/src/listallkeysjob_p.h @@ -1,65 +1,51 @@ /* - listallkeysjob.cpp + listallkeysjob_p.h This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2022,2023 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 +#ifndef __QGPGME_LISTALLKEYSJOB_P_H__ +#define __QGPGME_LISTALLKEYSJOB_P_H__ -#include "listallkeysjob.h" #include "job_p.h" -using namespace QGpgME; +#include "listallkeysjob.h" -namespace +namespace QGpgME { + struct ListAllKeysJobPrivate : public JobPrivate { - ListAllKeysJobPrivate() = default; - - ~ListAllKeysJobPrivate() override = default; - ListAllKeysJob::Options m_options = ListAllKeysJob::Default; }; -} -void ListAllKeysJob::setOptions(ListAllKeysJob::Options options) -{ - auto d = jobPrivate(this); - d->m_options = options; } -ListAllKeysJob::Options ListAllKeysJob::options() const -{ - auto d = jobPrivate(this); - return d->m_options; -} +#endif // __QGPGME_LISTALLKEYSJOB_P_H__ diff --git a/lang/qt/src/qgpgmechangeexpiryjob.cpp b/lang/qt/src/qgpgmechangeexpiryjob.cpp index 5d4e8360..6bffbc87 100644 --- a/lang/qt/src/qgpgmechangeexpiryjob.cpp +++ b/lang/qt/src/qgpgmechangeexpiryjob.cpp @@ -1,100 +1,121 @@ /* qgpgmechangeexpiryjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2008 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 + Copyright (c) 2021,2023 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 "qgpgmechangeexpiryjob.h" +#include "changeexpiryjob_p.h" + #include "context.h" #include "key.h" #include using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMEChangeExpiryJobPrivate : public ChangeExpiryJobPrivate +{ + QGpgMEChangeExpiryJob *q = nullptr; + +public: + QGpgMEChangeExpiryJobPrivate(QGpgMEChangeExpiryJob *qq) + : q{qq} + { + } + + ~QGpgMEChangeExpiryJobPrivate() override = default; +}; + +} + QGpgMEChangeExpiryJob::QGpgMEChangeExpiryJob(Context *context) : mixin_type(context) { + setJobPrivate(this, std::unique_ptr{new QGpgMEChangeExpiryJobPrivate{this}}); lateInitialization(); } QGpgMEChangeExpiryJob::~QGpgMEChangeExpiryJob() {} static QGpgMEChangeExpiryJob::result_type change_expiry(Context *ctx, const Key &key, const QDateTime &expiry, const std::vector &subkeys, ChangeExpiryJob::Options options) { // convert expiry to "seconds from now"; use 1 second from now if expiry is before the current datetime const unsigned long expires = expiry.isValid() ? std::max(QDateTime::currentDateTime().secsTo(expiry), 1) : 0; // updating the expiration date of the primary key and the subkeys needs to be done in two steps // because --quick-set-expire does not support updating the expiration date of both at the same time if (subkeys.empty() || (options & ChangeExpiryJob::UpdatePrimaryKey)) { // update the expiration date of the primary key auto err = ctx->setExpire(key, expires); if (err) { return std::make_tuple(err, QString(), Error()); } } GpgME::Error err; if (!subkeys.empty()) { // update the expiration date of the specified subkeys err = ctx->setExpire(key, expires, subkeys); } else if (options & ChangeExpiryJob::UpdateAllSubkeys) { // update the expiration date of all subkeys err = ctx->setExpire(key, expires, {}, Context::SetExpireAllSubkeys); } return std::make_tuple(err, QString(), Error()); } Error QGpgMEChangeExpiryJob::start(const Key &key, const QDateTime &expiry) { return start(key, expiry, std::vector()); } Error QGpgMEChangeExpiryJob::start(const Key &key, const QDateTime &expiry, const std::vector &subkeys) { run(std::bind(&change_expiry, std::placeholders::_1, key, expiry, subkeys, options())); return Error(); } #include "qgpgmechangeexpiryjob.moc" diff --git a/lang/qt/src/qgpgmeencryptjob.cpp b/lang/qt/src/qgpgmeencryptjob.cpp index cd544965..ae33db1d 100644 --- a/lang/qt/src/qgpgmeencryptjob.cpp +++ b/lang/qt/src/qgpgmeencryptjob.cpp @@ -1,184 +1,205 @@ /* qgpgmeencryptjob.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 - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2022,2023 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 "qgpgmeencryptjob.h" +#include "encryptjob_p.h" + #include "dataprovider.h" #include "context.h" #include "encryptionresult.h" #include "data.h" #include #include #include using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMEEncryptJobPrivate : public EncryptJobPrivate +{ + QGpgMEEncryptJob *q = nullptr; + +public: + QGpgMEEncryptJobPrivate(QGpgMEEncryptJob *qq) + : q{qq} + { + } + + ~QGpgMEEncryptJobPrivate() override = default; +}; + +} + QGpgMEEncryptJob::QGpgMEEncryptJob(Context *context) : mixin_type(context), mOutputIsBase64Encoded(false) { + setJobPrivate(this, std::unique_ptr{new QGpgMEEncryptJobPrivate{this}}); lateInitialization(); } QGpgMEEncryptJob::~QGpgMEEncryptJob() {} void QGpgMEEncryptJob::setOutputIsBase64Encoded(bool on) { mOutputIsBase64Encoded = on; } static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread, const std::vector &recipients, const std::weak_ptr &plainText_, const std::weak_ptr &cipherText_, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, const QString &fileName) { const std::shared_ptr plainText = plainText_.lock(); const std::shared_ptr cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); const _detail::ToThreadMover ptMover(plainText, thread); QGpgME::QIODeviceDataProvider in(plainText); Data indata(&in); const auto pureFileName = QFileInfo{fileName}.fileName().toStdString(); if (!pureFileName.empty()) { indata.setFileName(pureFileName.c_str()); } if (!cipherText) { QGpgME::QByteArrayDataProvider out; Data outdata(&out); if (outputIsBsse64Encoded) { outdata.setEncoding(Data::Base64Encoding); } const EncryptionResult res = ctx->encrypt(recipients, indata, outdata, eflags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, out.data(), log, ae); } else { QGpgME::QIODeviceDataProvider out(cipherText); Data outdata(&out); if (outputIsBsse64Encoded) { outdata.setEncoding(Data::Base64Encoding); } const EncryptionResult res = ctx->encrypt(recipients, indata, outdata, eflags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, QByteArray(), log, ae); } } static QGpgMEEncryptJob::result_type encrypt_qba(Context *ctx, const std::vector &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, const QString &fileName) { const std::shared_ptr buffer(new QBuffer); buffer->setData(plainText); if (!buffer->open(QIODevice::ReadOnly)) { assert(!"This should never happen: QBuffer::open() failed"); } return encrypt(ctx, nullptr, recipients, buffer, std::shared_ptr(), eflags, outputIsBsse64Encoded, fileName); } Error QGpgMEEncryptJob::start(const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust) { run(std::bind(&encrypt_qba, std::placeholders::_1, recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded, fileName())); return Error(); } void QGpgMEEncryptJob::start(const std::vector &recipients, const std::shared_ptr &plainText, const std::shared_ptr &cipherText, const Context::EncryptionFlags eflags) { run(std::bind(&encrypt, std::placeholders::_1, std::placeholders::_2, recipients, std::placeholders::_3, std::placeholders::_4, eflags, mOutputIsBase64Encoded, fileName()), plainText, cipherText); } EncryptionResult QGpgMEEncryptJob::exec(const std::vector &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, QByteArray &cipherText) { const result_type r = encrypt_qba(context(), recipients, plainText, eflags, mOutputIsBase64Encoded, fileName()); cipherText = std::get<1>(r); resultHook(r); return mResult; } void QGpgMEEncryptJob::start(const std::vector &recipients, const std::shared_ptr &plainText, const std::shared_ptr &cipherText, bool alwaysTrust) { return start(recipients, plainText, cipherText, alwaysTrust ? Context::AlwaysTrust : Context::None); } EncryptionResult QGpgMEEncryptJob::exec(const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText) { return exec(recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, cipherText); } void QGpgMEEncryptJob::resultHook(const result_type &tuple) { mResult = std::get<0>(tuple); } #if 0 void QGpgMEEncryptJob::showErrorDialog(QWidget *parent, const QString &caption) const { if (mResult.error() && !mResult.error().isCanceled()) { MessageBox::error(parent, mResult, this, caption); } } #endif #include "qgpgmeencryptjob.moc" diff --git a/lang/qt/src/qgpgmeimportjob.cpp b/lang/qt/src/qgpgmeimportjob.cpp index d609c5f1..e3fd251b 100644 --- a/lang/qt/src/qgpgmeimportjob.cpp +++ b/lang/qt/src/qgpgmeimportjob.cpp @@ -1,134 +1,157 @@ /* qgpgmeimportjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH + Copyright (c) 2023 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 "qgpgmeimportjob.h" +#include "importjob_p.h" + #include "dataprovider.h" #include #include #include using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMEImportJobPrivate : public ImportJobPrivate +{ + QGpgMEImportJob *q = nullptr; + +public: + QGpgMEImportJobPrivate(QGpgMEImportJob *qq) + : q{qq} + { + } + + ~QGpgMEImportJobPrivate() override = default; +}; + +} + QGpgMEImportJob::QGpgMEImportJob(Context *context) : mixin_type(context) { + setJobPrivate(this, std::unique_ptr{new QGpgMEImportJobPrivate{this}}); lateInitialization(); } QGpgMEImportJob::~QGpgMEImportJob() = default; static const char *originToString(Key::Origin origin) { static const std::map mapping = { { Key::OriginUnknown, "unknown" }, { Key::OriginKS, "ks" }, { Key::OriginDane, "dane" }, { Key::OriginWKD, "wkd" }, { Key::OriginURL, "url" }, { Key::OriginFile, "file" }, { Key::OriginSelf, "self" }, }; const auto it = mapping.find(origin); return (it != std::end(mapping)) ? it->second : nullptr; } static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &certData, const QString &importFilter, Key::Origin keyOrigin, const QString &keyOriginUrl) { if (!importFilter.isEmpty()) { ctx->setFlag("import-filter", importFilter.toStdString().c_str()); } if (keyOrigin != Key::OriginUnknown) { if (const auto origin = originToString(keyOrigin)) { std::string value{origin}; if (!keyOriginUrl.isEmpty()) { value += ","; value += keyOriginUrl.toStdString(); } ctx->setFlag("key-origin", value.c_str()); } } QGpgME::QByteArrayDataProvider dp(certData); Data data(&dp); ImportResult res = ctx->importKeys(data); // HACK: If the import failed with an error, then check if res.imports() // contains only import statuses with "bad passphrase" error; if yes, this // means that the user probably entered a wrong password to decrypt an // encrypted key for import. In this case, return a result with "bad // passphrase" error instead of the original error. // We check if all import statuses instead of any import status has a // "bad passphrase" error to avoid breaking imports that partially worked. // See https://dev.gnupg.org/T5713. const auto imports = res.imports(); if (res.error() && !imports.empty() && std::all_of(std::begin(imports), std::end(imports), [](const Import &import) { return import.error().code() == GPG_ERR_BAD_PASSPHRASE; })) { res = ImportResult{Error{GPG_ERR_BAD_PASSPHRASE}}; } Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } Error QGpgMEImportJob::start(const QByteArray &certData) { run(std::bind(&import_qba, std::placeholders::_1, certData, importFilter(), keyOrigin(), keyOriginUrl())); return Error(); } GpgME::ImportResult QGpgME::QGpgMEImportJob::exec(const QByteArray &keyData) { const result_type r = import_qba(context(), keyData, importFilter(), keyOrigin(), keyOriginUrl()); resultHook(r); return mResult; } // PENDING(marc) implement showErrorDialog() void QGpgME::QGpgMEImportJob::resultHook(const result_type &tuple) { mResult = std::get<0>(tuple); } #include "qgpgmeimportjob.moc" diff --git a/lang/qt/src/qgpgmelistallkeysjob.cpp b/lang/qt/src/qgpgmelistallkeysjob.cpp index 2d1dc091..4bd7d8ba 100644 --- a/lang/qt/src/qgpgmelistallkeysjob.cpp +++ b/lang/qt/src/qgpgmelistallkeysjob.cpp @@ -1,228 +1,249 @@ /* qgpgmelistallkeysjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2022,2023 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 "qgpgmelistallkeysjob.h" +#include "listallkeysjob_p.h" + #include "debug.h" #include "key.h" #include "context.h" #include "engineinfo.h" #include "global.h" #include "keylistresult.h" #include "qgpgme_debug.h" #include #include #include #include #include using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMEListAllKeysJobPrivate : public ListAllKeysJobPrivate +{ + QGpgMEListAllKeysJob *q = nullptr; + +public: + QGpgMEListAllKeysJobPrivate(QGpgMEListAllKeysJob *qq) + : q{qq} + { + } + + ~QGpgMEListAllKeysJobPrivate() override = default; +}; + +} + QGpgMEListAllKeysJob::QGpgMEListAllKeysJob(Context *context) : mixin_type(context), mResult() { + setJobPrivate(this, std::unique_ptr{new QGpgMEListAllKeysJobPrivate{this}}); lateInitialization(); } QGpgMEListAllKeysJob::~QGpgMEListAllKeysJob() {} namespace { static KeyListResult do_list_keys_legacy(Context *ctx, std::vector &keys, bool secretOnly) { const char **pat = nullptr; if (const Error err = ctx->startKeyListing(pat, secretOnly)) { return KeyListResult(nullptr, err); } Error err; do { keys.push_back(ctx->nextKey(err)); } while (!err); keys.pop_back(); const KeyListResult result = ctx->endKeyListing(); ctx->cancelPendingOperation(); return result; } template ForwardIterator unique_by_merge(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) { first = std::adjacent_find(first, last, pred); if (first == last) { return last; } ForwardIterator dest = first; dest->mergeWith(*++first); while (++first != last) if (pred(*dest, *first)) { dest->mergeWith(*first); } else { *++dest = *first; } return ++dest; } static void merge_keys(std::vector &merged, std::vector &pub, std::vector &sec) { merged.reserve(pub.size() + sec.size()); std::merge(pub.begin(), pub.end(), sec.begin(), sec.end(), std::back_inserter(merged), ByFingerprint()); merged.erase(unique_by_merge(merged.begin(), merged.end(), ByFingerprint()), merged.end()); } static QGpgMEListAllKeysJob::result_type list_keys_legacy(Context *ctx, bool mergeKeys) { std::vector pub, sec, merged; KeyListResult r; r.mergeWith(do_list_keys_legacy(ctx, pub, false)); std::sort(pub.begin(), pub.end(), ByFingerprint()); r.mergeWith(do_list_keys_legacy(ctx, sec, true)); std::sort(sec.begin(), sec.end(), ByFingerprint()); if (mergeKeys) { merge_keys(merged, pub, sec); } else { merged.swap(pub); } return std::make_tuple(r, merged, sec, QString(), Error()); } static KeyListResult do_list_keys(Context *ctx, std::vector &keys) { const unsigned int keyListMode = ctx->keyListMode(); ctx->addKeyListMode(KeyListMode::WithSecret); const char **pat = nullptr; if (const Error err = ctx->startKeyListing(pat)) { ctx->setKeyListMode(keyListMode); return KeyListResult(nullptr, err); } Error err; do { keys.push_back(ctx->nextKey(err)); } while (!err); keys.pop_back(); const KeyListResult result = ctx->endKeyListing(); ctx->setKeyListMode(keyListMode); ctx->cancelPendingOperation(); return result; } static QGpgMEListAllKeysJob::result_type list_keys(Context *ctx, bool mergeKeys, ListAllKeysJob::Options options) { if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.0") { return list_keys_legacy(ctx, mergeKeys); } if (options & ListAllKeysJob::DisableAutomaticTrustDatabaseCheck) { auto err = ctx->setFlag("no-auto-check-trustdb", "1"); if (err) { // ignore error, but log a warning qCWarning(QGPGME_LOG) << "Setting context flag no-auto-check-trustdb failed:" << err; } } std::vector keys; KeyListResult r = do_list_keys(ctx, keys); std::sort(keys.begin(), keys.end(), ByFingerprint()); std::vector sec; std::copy_if(keys.begin(), keys.end(), std::back_inserter(sec), [](const Key &key) { return key.hasSecret(); }); return std::make_tuple(r, keys, sec, QString(), Error()); } } Error QGpgMEListAllKeysJob::start(bool mergeKeys) { run(std::bind(&list_keys, std::placeholders::_1, mergeKeys, options())); return Error(); } KeyListResult QGpgMEListAllKeysJob::exec(std::vector &pub, std::vector &sec, bool mergeKeys) { const result_type r = list_keys(context(), mergeKeys, options()); resultHook(r); pub = std::get<1>(r); sec = std::get<2>(r); return std::get<0>(r); } void QGpgMEListAllKeysJob::resultHook(const result_type &tuple) { mResult = std::get<0>(tuple); } #if 0 void QGpgMEListAllKeysJob::showErrorDialog(QWidget *parent, const QString &caption) const { if (!mResult.error() || mResult.error().isCanceled()) { return; } const QString msg = i18n("

An error occurred while fetching " "the keys from the backend:

" "

%1

", QString::fromLocal8Bit(mResult.error().asString())); KMessageBox::error(parent, msg, caption); } #endif #include "qgpgmelistallkeysjob.moc" diff --git a/lang/qt/src/qgpgmesignencryptjob.cpp b/lang/qt/src/qgpgmesignencryptjob.cpp index 5466c54e..4a1082a9 100644 --- a/lang/qt/src/qgpgmesignencryptjob.cpp +++ b/lang/qt/src/qgpgmesignencryptjob.cpp @@ -1,183 +1,204 @@ /* qgpgmesignencryptjob.cpp 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 - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2022,2023 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 "qgpgmesignencryptjob.h" +#include "signencryptjob_p.h" + #include "dataprovider.h" #include "context.h" #include "data.h" #include "key.h" #include "exception.h" #include #include #include using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMESignEncryptJobPrivate : public SignEncryptJobPrivate +{ + QGpgMESignEncryptJob *q = nullptr; + +public: + QGpgMESignEncryptJobPrivate(QGpgMESignEncryptJob *qq) + : q{qq} + { + } + + ~QGpgMESignEncryptJobPrivate() override = default; +}; + +} + QGpgMESignEncryptJob::QGpgMESignEncryptJob(Context *context) : mixin_type(context), mOutputIsBase64Encoded(false) { + setJobPrivate(this, std::unique_ptr{new QGpgMESignEncryptJobPrivate{this}}); lateInitialization(); } QGpgMESignEncryptJob::~QGpgMESignEncryptJob() {} void QGpgMESignEncryptJob::setOutputIsBase64Encoded(bool on) { mOutputIsBase64Encoded = on; } static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thread, const std::vector &signers, const std::vector &recipients, const std::weak_ptr &plainText_, const std::weak_ptr &cipherText_, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, const QString &fileName) { const std::shared_ptr &plainText = plainText_.lock(); const std::shared_ptr &cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); const _detail::ToThreadMover ptMover(plainText, thread); QGpgME::QIODeviceDataProvider in(plainText); Data indata(&in); const auto pureFileName = QFileInfo{fileName}.fileName().toStdString(); if (!pureFileName.empty()) { indata.setFileName(pureFileName.c_str()); } ctx->clearSigningKeys(); Q_FOREACH (const Key &signer, signers) if (!signer.isNull()) if (const Error err = ctx->addSigningKey(signer)) { return std::make_tuple(SigningResult(err), EncryptionResult(), QByteArray(), QString(), Error()); } if (!cipherText) { QGpgME::QByteArrayDataProvider out; Data outdata(&out); if (outputIsBsse64Encoded) { outdata.setEncoding(Data::Base64Encoding); } const std::pair res = ctx->signAndEncrypt(recipients, indata, outdata, eflags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res.first, res.second, out.data(), log, ae); } else { QGpgME::QIODeviceDataProvider out(cipherText); Data outdata(&out); if (outputIsBsse64Encoded) { outdata.setEncoding(Data::Base64Encoding); } const std::pair res = ctx->signAndEncrypt(recipients, indata, outdata, eflags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res.first, res.second, QByteArray(), log, ae); } } static QGpgMESignEncryptJob::result_type sign_encrypt_qba(Context *ctx, const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, bool outputIsBsse64Encoded, const QString &fileName) { const std::shared_ptr buffer(new QBuffer); buffer->setData(plainText); if (!buffer->open(QIODevice::ReadOnly)) { assert(!"This should never happen: QBuffer::open() failed"); } return sign_encrypt(ctx, nullptr, signers, recipients, buffer, std::shared_ptr(), eflags, outputIsBsse64Encoded, fileName); } Error QGpgMESignEncryptJob::start(const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust) { run(std::bind(&sign_encrypt_qba, std::placeholders::_1, signers, recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, mOutputIsBase64Encoded, fileName())); return Error(); } void QGpgMESignEncryptJob::start(const std::vector &signers, const std::vector &recipients, const std::shared_ptr &plainText, const std::shared_ptr &cipherText, const Context::EncryptionFlags eflags) { run(std::bind(&sign_encrypt, std::placeholders::_1, std::placeholders::_2, signers, recipients, std::placeholders::_3, std::placeholders::_4, eflags, mOutputIsBase64Encoded, fileName()), plainText, cipherText); } void QGpgMESignEncryptJob::start(const std::vector &signers, const std::vector &recipients, const std::shared_ptr &plainText, const std::shared_ptr &cipherText, bool alwaysTrust) { return start(signers, recipients, plainText, cipherText, alwaysTrust ? Context::AlwaysTrust : Context::None); } std::pair QGpgMESignEncryptJob::exec(const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, const Context::EncryptionFlags eflags, QByteArray &cipherText) { const result_type r = sign_encrypt_qba(context(), signers, recipients, plainText, eflags, mOutputIsBase64Encoded, fileName()); cipherText = std::get<2>(r); resultHook(r); return mResult; } std::pair QGpgMESignEncryptJob::exec(const std::vector &signers, const std::vector &recipients, const QByteArray &plainText, bool alwaysTrust, QByteArray &cipherText) { return exec(signers, recipients, plainText, alwaysTrust ? Context::AlwaysTrust : Context::None, cipherText); } #if 0 TODO port? void QGpgMESignEncryptJob::showErrorDialog(QWidget *parent, const QString &caption) const { if ((mResult.first.error() && !mResult.first.error().isCanceled()) || (mResult.second.error() && !mResult.second.error().isCanceled())) { MessageBox::error(parent, mResult.first, mResult.second, this, caption); } } #endif void QGpgMESignEncryptJob::resultHook(const result_type &tuple) { mResult = std::make_pair(std::get<0>(tuple), std::get<1>(tuple)); } #include "qgpgmesignencryptjob.moc" diff --git a/lang/qt/src/signencryptjob.cpp b/lang/qt/src/signencryptjob.cpp index aa02fca3..2f4c5fd6 100644 --- a/lang/qt/src/signencryptjob.cpp +++ b/lang/qt/src/signencryptjob.cpp @@ -1,61 +1,53 @@ /* signencryptjob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2022 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 "signencryptjob.h" -#include "job_p.h" +#include "signencryptjob_p.h" using namespace QGpgME; -namespace -{ -struct SignEncryptJobPrivate : public JobPrivate -{ - QString m_fileName; -}; -} - void SignEncryptJob::setFileName(const QString &fileName) { auto d = jobPrivate(this); d->m_fileName = fileName; } QString SignEncryptJob::fileName() const { auto d = jobPrivate(this); return d->m_fileName; } diff --git a/lang/qt/src/signencryptjob.cpp b/lang/qt/src/signencryptjob_p.h similarity index 78% copy from lang/qt/src/signencryptjob.cpp copy to lang/qt/src/signencryptjob_p.h index aa02fca3..85afae26 100644 --- a/lang/qt/src/signencryptjob.cpp +++ b/lang/qt/src/signencryptjob_p.h @@ -1,61 +1,49 @@ /* - signencryptjob.cpp + signencryptjob_p.h This file is part of qgpgme, the Qt API binding for gpgme - Copyright (c) 2022 g10 Code GmbH + Copyright (c) 2022,2023 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 +#ifndef __QGPGME_SIGNENCRYPTJOB_P_H__ +#define __QGPGME_SIGNENCRYPTJOB_P_H__ -#include "signencryptjob.h" #include "job_p.h" -using namespace QGpgME; - -namespace +namespace QGpgME { + struct SignEncryptJobPrivate : public JobPrivate { QString m_fileName; }; -} -void SignEncryptJob::setFileName(const QString &fileName) -{ - auto d = jobPrivate(this); - d->m_fileName = fileName; } -QString SignEncryptJob::fileName() const -{ - auto d = jobPrivate(this); - return d->m_fileName; -} +#endif // __QGPGME_SIGNENCRYPTJOB_P_H__