diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index 5e07f787..9e01a0ea 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -1,228 +1,228 @@ /* 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 "encryptjob.h" #include "decryptjob.h" #include "decryptverifyjob.h" #include "signjob.h" #include "signkeyjob.h" #include "signencryptjob.h" #include "verifydetachedjob.h" #include "verifyopaquejob.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); } void QGpgME::Job::startNow() { auto d = getJobPrivate(this); Q_ASSERT(d && "This Job class has no JobPrivate class"); - d->start(); + 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(EncryptJob) make_job_subclass(DecryptJob) make_job_subclass(DecryptVerifyJob) make_job_subclass(SignJob) make_job_subclass(SignEncryptJob) make_job_subclass(SignKeyJob) make_job_subclass(VerifyDetachedJob) make_job_subclass(VerifyOpaqueJob) 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 "encryptjob.moc" #include "decryptjob.moc" #include "decryptverifyjob.moc" #include "signjob.moc" #include "signencryptjob.moc" #include "signkeyjob.moc" #include "verifydetachedjob.moc" #include "verifyopaquejob.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/job_p.h b/lang/qt/src/job_p.h index 43063dd1..e4397465 100644 --- a/lang/qt/src/job_p.h +++ b/lang/qt/src/job_p.h @@ -1,96 +1,96 @@ /* 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 "qgpgme_debug.h" #include namespace QGpgME { // Base class for pimpl classes for Job subclasses class JobPrivate { public: virtual ~JobPrivate() {} - virtual void start() = 0; + virtual void startNow() = 0; }; // 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); const JobPrivate *getJobPrivate(const Job *job); JobPrivate *getJobPrivate(Job *job); template static const T *jobPrivate(const Job *job) { auto d = getJobPrivate(job); return dynamic_cast(d); } template static T *jobPrivate(Job *job) { auto d = getJobPrivate(job); return dynamic_cast(d); } // Helper for the archive job classes template void emitArchiveProgressSignals(JobClass *job, const QString &what, int type, int current, int total) { if (what != QLatin1String{"gpgtar"}) { return; } switch (type) { case 'c': Q_EMIT job->fileProgress(current, total); break; case 's': Q_EMIT job->dataProgress(current, total); break; default: qCDebug(QGPGME_LOG) << job << __func__ << "Received progress for gpgtar with unknown type" << char(type); }; } } #endif // __QGPGME_JOB_P_H__ diff --git a/lang/qt/src/qgpgmechangeexpiryjob.cpp b/lang/qt/src/qgpgmechangeexpiryjob.cpp index 4d928bd9..83a5b172 100644 --- a/lang/qt/src/qgpgmechangeexpiryjob.cpp +++ b/lang/qt/src/qgpgmechangeexpiryjob.cpp @@ -1,127 +1,127 @@ /* 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,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; private: - void start() override + void startNow() override { q->run(); } }; } 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/qgpgmedecryptverifyarchivejob.cpp b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp index 68c97f87..e47ca5e6 100644 --- a/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp +++ b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp @@ -1,125 +1,125 @@ /* qgpgmedecryptverifyarchivejob.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 "qgpgmedecryptverifyarchivejob.h" #include "dataprovider.h" #include "decryptverifyarchivejob_p.h" #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMEDecryptVerifyArchiveJobPrivate : public DecryptVerifyArchiveJobPrivate { QGpgMEDecryptVerifyArchiveJob *q = nullptr; public: QGpgMEDecryptVerifyArchiveJobPrivate(QGpgMEDecryptVerifyArchiveJob *qq) : q{qq} { } ~QGpgMEDecryptVerifyArchiveJobPrivate() override = default; private: - void start() override + void startNow() override { q->run(); } }; } QGpgMEDecryptVerifyArchiveJob::QGpgMEDecryptVerifyArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMEDecryptVerifyArchiveJobPrivate{this}}); lateInitialization(); connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { emitArchiveProgressSignals(this, what, type, current, total); }); } static QGpgMEDecryptVerifyArchiveJob::result_type decrypt_verify(Context *ctx, QThread *thread, const std::weak_ptr &cipherText_, const QString &outputDirectory) { const std::shared_ptr cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); QGpgME::QIODeviceDataProvider in{cipherText}; Data indata(&in); if (!cipherText->isSequential()) { indata.setSizeHint(cipherText->size()); } Data outdata; if (!outputDirectory.isEmpty()) { outdata.setFileName(outputDirectory.toStdString()); } const auto res = ctx->decryptAndVerify(indata, outdata, Context::DecryptArchive); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res.first, res.second, log, ae); } GpgME::Error QGpgMEDecryptVerifyArchiveJob::start(const std::shared_ptr &cipherText) { if (!cipherText) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&decrypt_verify, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, outputDirectory()), cipherText); return {}; } #include "qgpgmedecryptverifyarchivejob.moc" diff --git a/lang/qt/src/qgpgmeencryptarchivejob.cpp b/lang/qt/src/qgpgmeencryptarchivejob.cpp index 3dc5b433..2a7855c3 100644 --- a/lang/qt/src/qgpgmeencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmeencryptarchivejob.cpp @@ -1,134 +1,134 @@ /* qgpgmeencryptarchivejob.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,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 "qgpgmeencryptarchivejob.h" #include "dataprovider.h" #include "encryptarchivejob_p.h" #include "filelistdataprovider.h" #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMEEncryptArchiveJobPrivate : public EncryptArchiveJobPrivate { QGpgMEEncryptArchiveJob *q = nullptr; public: QGpgMEEncryptArchiveJobPrivate(QGpgMEEncryptArchiveJob *qq) : q{qq} { } ~QGpgMEEncryptArchiveJobPrivate() override = default; private: - void start() override + void startNow() override { q->run(); } }; } QGpgMEEncryptArchiveJob::QGpgMEEncryptArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMEEncryptArchiveJobPrivate{this}}); lateInitialization(); connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { emitArchiveProgressSignals(this, what, type, current, total); }); } static QGpgMEEncryptArchiveJob::result_type encrypt(Context *ctx, QThread *thread, const std::vector &recipients, const std::vector &paths, const std::weak_ptr &cipherText_, Context::EncryptionFlags flags, const QString &baseDirectory) { const std::shared_ptr cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); QGpgME::FileListDataProvider in{paths}; Data indata(&in); if (!baseDirectory.isEmpty()) { indata.setFileName(baseDirectory.toStdString()); } QGpgME::QIODeviceDataProvider out{cipherText}; Data outdata(&out); flags = static_cast(flags | Context::EncryptArchive); const EncryptionResult res = ctx->encrypt(recipients, indata, outdata, flags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } GpgME::Error QGpgMEEncryptArchiveJob::start(const std::vector &recipients, const std::vector &paths, const std::shared_ptr &cipherText, const GpgME::Context::EncryptionFlags flags) { if (!cipherText) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&encrypt, std::placeholders::_1, std::placeholders::_2, recipients, paths, std::placeholders::_3, flags, baseDirectory()), cipherText); return {}; } #include "qgpgmeencryptarchivejob.moc" diff --git a/lang/qt/src/qgpgmeencryptjob.cpp b/lang/qt/src/qgpgmeencryptjob.cpp index dffd3acb..8ad9cc2c 100644 --- a/lang/qt/src/qgpgmeencryptjob.cpp +++ b/lang/qt/src/qgpgmeencryptjob.cpp @@ -1,214 +1,214 @@ /* 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,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; private: - void start() override + void startNow() override { q->run(); } }; } 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); if (!plainText->isSequential()) { indata.setSizeHint(plainText->size()); } 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 9f09ca7c..239cb84c 100644 --- a/lang/qt/src/qgpgmeimportjob.cpp +++ b/lang/qt/src/qgpgmeimportjob.cpp @@ -1,169 +1,169 @@ /* 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; private: - void start() override + void startNow() override { q->run(); } }; } 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; } Error QGpgMEImportJob::startLater(const QByteArray &certData) { setWorkerFunction(std::bind(&import_qba, std::placeholders::_1, certData, importFilter(), keyOrigin(), keyOriginUrl())); return {}; } // 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 78ffaded..bc6ea0d7 100644 --- a/lang/qt/src/qgpgmelistallkeysjob.cpp +++ b/lang/qt/src/qgpgmelistallkeysjob.cpp @@ -1,255 +1,255 @@ /* 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,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; private: - void start() override + void startNow() override { q->run(); } }; } 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/qgpgmesignarchivejob.cpp b/lang/qt/src/qgpgmesignarchivejob.cpp index cd569f31..59614916 100644 --- a/lang/qt/src/qgpgmesignarchivejob.cpp +++ b/lang/qt/src/qgpgmesignarchivejob.cpp @@ -1,139 +1,139 @@ /* qgpgmesignarchivejob.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,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 "qgpgmesignarchivejob.h" #include "dataprovider.h" #include "signarchivejob_p.h" #include "filelistdataprovider.h" #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMESignArchiveJobPrivate : public SignArchiveJobPrivate { QGpgMESignArchiveJob *q = nullptr; public: QGpgMESignArchiveJobPrivate(QGpgMESignArchiveJob *qq) : q{qq} { } ~QGpgMESignArchiveJobPrivate() override = default; private: - void start() override + void startNow() override { q->run(); } }; } QGpgMESignArchiveJob::QGpgMESignArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMESignArchiveJobPrivate{this}}); lateInitialization(); connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { emitArchiveProgressSignals(this, what, type, current, total); }); } static QGpgMESignArchiveJob::result_type sign(Context *ctx, QThread *thread, const std::vector &signers, const std::vector &paths, const std::weak_ptr &output_, const QString &baseDirectory) { const std::shared_ptr output = output_.lock(); const _detail::ToThreadMover ctMover(output, thread); QGpgME::FileListDataProvider in{paths}; Data indata(&in); if (!baseDirectory.isEmpty()) { indata.setFileName(baseDirectory.toStdString()); } QGpgME::QIODeviceDataProvider out{output}; Data outdata(&out); ctx->clearSigningKeys(); for (const Key &signer : signers) { if (!signer.isNull()) { if (const Error err = ctx->addSigningKey(signer)) { return std::make_tuple(SigningResult{err}, QString{}, Error{}); } } } const SigningResult res = ctx->sign(indata, outdata, GpgME::SignArchive); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } GpgME::Error QGpgMESignArchiveJob::start(const std::vector &signers, const std::vector &paths, const std::shared_ptr &output) { if (!output) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&sign, std::placeholders::_1, std::placeholders::_2, signers, paths, std::placeholders::_3, baseDirectory()), output); return {}; } #include "qgpgmesignarchivejob.moc" diff --git a/lang/qt/src/qgpgmesignencryptarchivejob.cpp b/lang/qt/src/qgpgmesignencryptarchivejob.cpp index c5e00ef0..e7f5f30f 100644 --- a/lang/qt/src/qgpgmesignencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmesignencryptarchivejob.cpp @@ -1,153 +1,153 @@ /* qgpgmesignencryptarchivejob.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,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 "qgpgmesignencryptarchivejob.h" #include "dataprovider.h" #include "signencryptarchivejob_p.h" #include "filelistdataprovider.h" // #include #include // #include // // #include // #include // // #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMESignEncryptArchiveJobPrivate : public SignEncryptArchiveJobPrivate { QGpgMESignEncryptArchiveJob *q = nullptr; public: QGpgMESignEncryptArchiveJobPrivate(QGpgMESignEncryptArchiveJob *qq) : q{qq} { } ~QGpgMESignEncryptArchiveJobPrivate() override = default; private: - void start() override + void startNow() override { q->run(); } }; } QGpgMESignEncryptArchiveJob::QGpgMESignEncryptArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMESignEncryptArchiveJobPrivate{this}}); lateInitialization(); connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { emitArchiveProgressSignals(this, what, type, current, total); }); } static QGpgMESignEncryptArchiveJob::result_type sign_encrypt(Context *ctx, QThread *thread, const std::vector &signers, const std::vector &recipients, const std::vector &paths, const std::weak_ptr &cipherText_, Context::EncryptionFlags encryptionFlags, const QString &baseDirectory) { const std::shared_ptr cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); QGpgME::FileListDataProvider in{paths}; Data indata(&in); if (!baseDirectory.isEmpty()) { indata.setFileName(baseDirectory.toStdString()); } QGpgME::QIODeviceDataProvider out{cipherText}; Data outdata(&out); ctx->clearSigningKeys(); for (const Key &signer : signers) { if (!signer.isNull()) { if (const Error err = ctx->addSigningKey(signer)) { return std::make_tuple(SigningResult{err}, EncryptionResult{}, QString{}, Error{}); } } } encryptionFlags = static_cast(encryptionFlags | Context::EncryptArchive); const auto res = ctx->signAndEncrypt(recipients, indata, outdata, encryptionFlags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res.first, res.second, log, ae); } GpgME::Error QGpgMESignEncryptArchiveJob::start(const std::vector &signers, const std::vector &recipients, const std::vector &paths, const std::shared_ptr &cipherText, const GpgME::Context::EncryptionFlags encryptionFlags) { if (!cipherText) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&sign_encrypt, std::placeholders::_1, std::placeholders::_2, signers, recipients, paths, std::placeholders::_3, encryptionFlags, baseDirectory()), cipherText); return {}; } #include "qgpgmesignencryptarchivejob.moc" diff --git a/lang/qt/src/qgpgmesignencryptjob.cpp b/lang/qt/src/qgpgmesignencryptjob.cpp index e752c0bc..6a62ee86 100644 --- a/lang/qt/src/qgpgmesignencryptjob.cpp +++ b/lang/qt/src/qgpgmesignencryptjob.cpp @@ -1,213 +1,213 @@ /* 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,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; private: - void start() override + void startNow() override { q->run(); } }; } 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); if (!plainText->isSequential()) { indata.setSizeHint(plainText->size()); } 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"