diff options
author | Ingo Klöcker <[email protected]> | 2023-12-22 09:05:16 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2023-12-22 09:05:16 +0000 |
commit | e77a8ac0cc2ef356ef7e9da2793329432caf7406 (patch) | |
tree | 03f18a6d6f94013898e9ffd36cecf28651e1699a /lang/qt/src/qgpgmeverifyopaquejob.cpp | |
parent | qt: Support decryption (with verification) directly to/from files (diff) | |
download | gpgme-e77a8ac0cc2ef356ef7e9da2793329432caf7406.tar.gz gpgme-e77a8ac0cc2ef356ef7e9da2793329432caf7406.zip |
qt: Support verification of opaque signed data directly to/from files
* lang/qt/src/Makefile.am: Add new files.
* lang/qt/src/job.cpp (VerifyOpaqueJob): Move definition of constructor
and destructor and inclusion of the moc file to the corresponding .cpp
file.
* lang/qt/src/verifyopaquejob.cpp: New.
* lang/qt/src/verifyopaquejob.h (VerifyOpaqueJob): Add member
functions setInputFile, inputFile, setOutputFile, outputFile.
* lang/qt/src/verifyopaquejob_p.h: New.
* lang/qt/src/qgpgmeverifyopaquejob.cpp (class
QGpgMEVerifyOpaqueJobPrivate): New.
(QGpgMEVerifyOpaqueJob::QGpgMEVerifyOpaqueJob): Instantiate private
job class.
(verify_from_filename): New.
* lang/qt/tests/Makefile.am: Add new test program.
* lang/qt/tests/run-verifyopaquejob.cpp: New.
--
This makes it possible to tell gpg to read the input and write the
output directly to a specified file bypassing GpgME's Data IO when
verifying an opaque signed (or clear signed) file.
GnuPG-bug-id: 6550
Diffstat (limited to 'lang/qt/src/qgpgmeverifyopaquejob.cpp')
-rw-r--r-- | lang/qt/src/qgpgmeverifyopaquejob.cpp | 88 |
1 files changed, 82 insertions, 6 deletions
diff --git a/lang/qt/src/qgpgmeverifyopaquejob.cpp b/lang/qt/src/qgpgmeverifyopaquejob.cpp index 01372e07..2ff53227 100644 --- a/lang/qt/src/qgpgmeverifyopaquejob.cpp +++ b/lang/qt/src/qgpgmeverifyopaquejob.cpp @@ -39,22 +39,51 @@ #include "qgpgmeverifyopaquejob.h" #include "dataprovider.h" +#include "util.h" +#include "verifyopaquejob_p.h" -#include "context.h" -#include "verificationresult.h" -#include "data.h" +#include <context.h> +#include <data.h> +#include <verificationresult.h> #include <QBuffer> - +#include <QFile> #include <cassert> using namespace QGpgME; using namespace GpgME; +namespace +{ + +class QGpgMEVerifyOpaqueJobPrivate : public VerifyOpaqueJobPrivate +{ + QGpgMEVerifyOpaqueJob *q = nullptr; + +public: + QGpgMEVerifyOpaqueJobPrivate(QGpgMEVerifyOpaqueJob *qq) + : q{qq} + { + } + + ~QGpgMEVerifyOpaqueJobPrivate() override = default; + +private: + GpgME::Error startIt() override; + + void startNow() override + { + q->run(); + } +}; + +} + QGpgMEVerifyOpaqueJob::QGpgMEVerifyOpaqueJob(Context *context) : mixin_type(context) { + setJobPrivate(this, std::unique_ptr<QGpgMEVerifyOpaqueJobPrivate>{new QGpgMEVerifyOpaqueJobPrivate{this}}); lateInitialization(); } @@ -105,6 +134,41 @@ static QGpgMEVerifyOpaqueJob::result_type verify_opaque_qba(Context *ctx, const return verify_opaque(ctx, nullptr, buffer, std::shared_ptr<QIODevice>()); } +static QGpgMEVerifyOpaqueJob::result_type verify_from_filename(Context *ctx, + const QString &inputFilePath, + const QString &outputFilePath) +{ + Data indata; +#ifdef Q_OS_WIN + indata.setFileName(inputFilePath().toUtf8().constData()); +#else + indata.setFileName(QFile::encodeName(inputFilePath).constData()); +#endif + + PartialFileGuard partFileGuard{outputFilePath}; + if (partFileGuard.tempFileName().isEmpty()) { + return std::make_tuple(VerificationResult{Error::fromCode(GPG_ERR_EEXIST)}, QByteArray{}, QString{}, Error{}); + } + + Data outdata; +#ifdef Q_OS_WIN + outdata.setFileName(partFileGuard.tempFileName().toUtf8().constData()); +#else + outdata.setFileName(QFile::encodeName(partFileGuard.tempFileName()).constData()); +#endif + + const auto verificationResult = ctx->verifyOpaqueSignature(indata, outdata); + + if (!verificationResult.error().code()) { + // the operation succeeded -> save the result under the requested file name + partFileGuard.commit(); + } + + Error ae; + const QString log = _detail::audit_log_as_html(ctx, ae); + return std::make_tuple(verificationResult, QByteArray{}, log, ae); +} + Error QGpgMEVerifyOpaqueJob::start(const QByteArray &signedData) { run(std::bind(&verify_opaque_qba, std::placeholders::_1, signedData)); @@ -124,10 +188,22 @@ GpgME::VerificationResult QGpgME::QGpgMEVerifyOpaqueJob::exec(const QByteArray & return mResult; } -//PENDING(marc) implement showErrorDialog() - void QGpgME::QGpgMEVerifyOpaqueJob::resultHook(const result_type &tuple) { mResult = std::get<0>(tuple); } + +GpgME::Error QGpgMEVerifyOpaqueJobPrivate::startIt() +{ + if (m_inputFilePath.isEmpty() || m_outputFilePath.isEmpty()) { + return Error::fromCode(GPG_ERR_INV_VALUE); + } + + q->run([=](Context *ctx) { + return verify_from_filename(ctx, m_inputFilePath, m_outputFilePath); + }); + + return {}; +} + #include "qgpgmeverifyopaquejob.moc" |