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
This commit is contained in:
Ingo Klöcker 2022-01-04 15:56:34 +01:00
parent e5c7fc3e02
commit 04723a6e96
3 changed files with 19 additions and 1 deletions

View File

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

View File

@ -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

View File

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