From 04723a6e96be77dbc43bf71c54e268424a1823ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 4 Jan 2022 15:56:34 +0100 Subject: [PATCH] qt: Add factory function for secret subkey export job * lang/qt/src/protocol.h (class Protocol): Add member function secretSubkeyExportJob. * lang/qt/src/protocol_p.h (Protocol::secretSubkeyExportJob): Implement. * lang/qt/tests/run-exportjob.cpp (showUsageAndExitWithCode): Print new option. (createExportJob): Create secret subkey export job if requested. (main): New option --secret-subkey. -- GnuPG-bug-id: 5757 --- lang/qt/src/protocol.h | 1 + lang/qt/src/protocol_p.h | 11 +++++++++++ lang/qt/tests/run-exportjob.cpp | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lang/qt/src/protocol.h b/lang/qt/src/protocol.h index 35789414..e3caac28 100644 --- a/lang/qt/src/protocol.h +++ b/lang/qt/src/protocol.h @@ -128,6 +128,7 @@ public: virtual ExportJob *publicKeyExportJob(bool armor = false) const = 0; // the second parameter is ignored; the passphrase in the exported file is always utf-8 encoded virtual ExportJob *secretKeyExportJob(bool armor = false, const QString & = QString()) const = 0; + virtual ExportJob *secretSubkeyExportJob(bool armor = false) const = 0; virtual DownloadJob *downloadJob(bool armor = false) const = 0; virtual DeleteJob *deleteJob() const = 0; virtual SignEncryptJob *signEncryptJob(bool armor = false, bool textMode = false) const = 0; diff --git a/lang/qt/src/protocol_p.h b/lang/qt/src/protocol_p.h index 054fec6e..08100a48 100644 --- a/lang/qt/src/protocol_p.h +++ b/lang/qt/src/protocol_p.h @@ -254,6 +254,17 @@ public: return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecret); } + QGpgME::ExportJob *secretSubkeyExportJob(bool armor) const Q_DECL_OVERRIDE + { + GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol); + if (!context) { + return nullptr; + } + + context->setArmor(armor); + return new QGpgME::QGpgMEExportJob(context, GpgME::Context::ExportSecretSubkey); + } + QGpgME::RefreshKeysJob *refreshKeysJob() const Q_DECL_OVERRIDE { if (mProtocol != GpgME::CMS) { // fixme: add support for gpg, too diff --git a/lang/qt/tests/run-exportjob.cpp b/lang/qt/tests/run-exportjob.cpp index 1a1617da..0f8fd8fd 100644 --- a/lang/qt/tests/run-exportjob.cpp +++ b/lang/qt/tests/run-exportjob.cpp @@ -52,13 +52,16 @@ static void showUsageAndExitWithCode(int exitCode) cerr << "Usage: run-exportjob [OPTION]... [PATTERN]...\n" "Options:\n" " --secret export secret keys instead of public keys\n" + " --secret-subkey export secret subkeys instead of public keys\n"; exit(exitCode); } static auto createExportJob(unsigned int mode) { - if (mode & Context::ExportSecret) { + if (mode & Context::ExportSecretSubkey) { + return QGpgME::openpgp()->secretSubkeyExportJob(/*armor=*/true); + } else if (mode & Context::ExportSecret) { return QGpgME::openpgp()->secretKeyExportJob(/*armor=*/true); } return QGpgME::openpgp()->publicKeyExportJob(/*armor=*/true); @@ -90,6 +93,9 @@ int main(int argc, char *argv[]) } else if (arg == QLatin1String{"--secret"}) { exportMode = Context::ExportSecret; arguments.pop_front(); + } else if (arg == QLatin1String{"--secret-subkey"}) { + exportMode = Context::ExportSecretSubkey; + arguments.pop_front(); } else { cerr << "Error: Invalid option " << arg.toStdString() << std::endl; showUsageAndExitWithCode(1);