diff options
author | Ingo Klöcker <[email protected]> | 2023-01-31 10:20:47 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2023-01-31 11:01:33 +0000 |
commit | 8c4436e73af369f79f125f56d020d01b184cafc6 (patch) | |
tree | 0b9d91b273067e03e1718c3687f11a63740f59bd /lang/qt/tests/run-encryptarchivejob.cpp | |
parent | qt,tests: Avoid leaking Context (diff) | |
download | gpgme-8c4436e73af369f79f125f56d020d01b184cafc6.tar.gz gpgme-8c4436e73af369f79f125f56d020d01b184cafc6.zip |
qt: Add job for creating encrypted signed archives
* lang/qt/src/signencryptarchivejob.cpp,
lang/qt/src/signencryptarchivejob.h,
lang/qt/src/signencryptarchivejob_p.h,
lang/qt/src/qgpgmesignencryptarchivejob.cpp,
lang/qt/src/qgpgmesignencryptarchivejob.h: New.
* lang/qt/src/protocol.h (class Protocol): Add pure virtual member
function signEncryptArchiveJob
* lang/qt/src/protocol_p.h (Protocol::signEncryptArchiveJob): ... and
implement it.
* lang/qt/src/Makefile.am: Update accordingly.
* lang/qt/tests/run-encryptarchivejob.cpp (displayName): Remove.
(CommandLineOptions): Initialize member armor. Add member sign.
(parseCommandLine): Update application description. Add and parse option
-s/--sign.
(main): Use SignEncryptArchiveJob if sign option is set.
--
GnuPG-bug-id: 6342
Diffstat (limited to 'lang/qt/tests/run-encryptarchivejob.cpp')
-rw-r--r-- | lang/qt/tests/run-encryptarchivejob.cpp | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/lang/qt/tests/run-encryptarchivejob.cpp b/lang/qt/tests/run-encryptarchivejob.cpp index e48af9f8..cdcfa17d 100644 --- a/lang/qt/tests/run-encryptarchivejob.cpp +++ b/lang/qt/tests/run-encryptarchivejob.cpp @@ -36,6 +36,7 @@ #include <protocol.h> #include <encryptarchivejob.h> +#include <signencryptarchivejob.h> #include <QCommandLineParser> #include <QCoreApplication> @@ -44,8 +45,8 @@ #include <context.h> #include <encryptionresult.h> +#include <signingresult.h> -#include <algorithm> #include <iostream> using namespace GpgME; @@ -55,20 +56,9 @@ std::ostream &operator<<(std::ostream &os, const QString &s) return os << s.toLocal8Bit().constData(); } -const char *displayName(Protocol protocol) -{ - switch (protocol) { - case GpgME::OpenPGP: - return "OpenPGP"; - case GpgME::CMS: - return "S/MIME"; - default: - return "Unknown protocol"; - } -} - struct CommandLineOptions { - bool armor; + bool armor = false; + bool sign = false; QString archiveName; QString baseDirectory; std::vector<QString> filesAndDirectories; @@ -79,9 +69,10 @@ CommandLineOptions parseCommandLine(const QStringList &arguments) CommandLineOptions options; QCommandLineParser parser; - parser.setApplicationDescription("Test program for EncryptArchiveJob"); + parser.setApplicationDescription("Test program for EncryptArchiveJob and SignEncryptArchiveJob"); parser.addHelpOption(); parser.addOptions({ + {{"s", "sign"}, "Sign archive before encryption."}, {{"o", "output"}, "Write output to FILE.", "FILE"}, {{"a", "armor"}, "Create ASCII armored output."}, {{"C", "directory"}, "Change to DIRECTORY before creating the archive.", "DIRECTORY"}, @@ -96,6 +87,7 @@ CommandLineOptions parseCommandLine(const QStringList &arguments) } options.armor = parser.isSet("armor"); + options.sign = parser.isSet("sign"); options.archiveName = parser.value("output"); options.baseDirectory = parser.value("directory"); std::copy(args.begin(), args.end(), std::back_inserter(options.filesAndDirectories)); @@ -136,22 +128,43 @@ int main(int argc, char **argv) return 1; } - auto job = QGpgME::openpgp()->encryptArchiveJob(options.armor); - if (!job) { - std::cerr << "Error: Could not create job" << std::endl; - return 1; - } - job->setBaseDirectory(options.baseDirectory); - QObject::connect(job, &QGpgME::EncryptArchiveJob::result, &app, [](const GpgME::EncryptionResult &result, const QString &auditLog, const GpgME::Error &) { - std::cerr << "Diagnostics: " << auditLog << std::endl; - std::cerr << "Result: " << result << std::endl; - qApp->quit(); - }); - - const auto err = job->start({}, options.filesAndDirectories, output, GpgME::Context::None); - if (err) { - std::cerr << "Error: Starting the job failed: " << err.asString() << std::endl; - return 1; + if (options.sign) { + auto job = QGpgME::openpgp()->signEncryptArchiveJob(options.armor); + if (!job) { + std::cerr << "Error: Could not create job" << std::endl; + return 1; + } + job->setBaseDirectory(options.baseDirectory); + QObject::connect(job, &QGpgME::SignEncryptArchiveJob::result, &app, [](const GpgME::SigningResult &signingResult, const GpgME::EncryptionResult &encryptionResult, const QString &auditLog, const GpgME::Error &) { + std::cerr << "Diagnostics: " << auditLog << std::endl; + std::cerr << "Signing Result: " << signingResult << std::endl; + std::cerr << "Encryption Result: " << encryptionResult << std::endl; + qApp->quit(); + }); + + const auto err = job->start({}, {}, options.filesAndDirectories, output, GpgME::Context::None); + if (err) { + std::cerr << "Error: Starting the job failed: " << err.asString() << std::endl; + return 1; + } + } else { + auto job = QGpgME::openpgp()->encryptArchiveJob(options.armor); + if (!job) { + std::cerr << "Error: Could not create job" << std::endl; + return 1; + } + job->setBaseDirectory(options.baseDirectory); + QObject::connect(job, &QGpgME::EncryptArchiveJob::result, &app, [](const GpgME::EncryptionResult &result, const QString &auditLog, const GpgME::Error &) { + std::cerr << "Diagnostics: " << auditLog << std::endl; + std::cerr << "Result: " << result << std::endl; + qApp->quit(); + }); + + const auto err = job->start({}, options.filesAndDirectories, output, GpgME::Context::None); + if (err) { + std::cerr << "Error: Starting the job failed: " << err.asString() << std::endl; + return 1; + } } return app.exec(); |