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);