From 690d967196d9f888e2b7c12d8c77ad752d7e15bf Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Thu, 16 Jul 2020 17:00:28 +0200 Subject: [PATCH] qt, cpp: Support export modes * lang/cpp/context.cpp, lang/cpp/context.h (Context::startPublicKeyExport, Context::exportPublicKeys): Extend with flags paramenter. (Context::ExportMode): New. * lang/qt/src/exportjob.h (ExportJob::setExportMode): New. * lang/qt/src/qgpgmeexportjob.cpp, lang/qt/src/qgpgmeexportjob.h: Update accordingly. -- This adds the C++ and Qt API for export modes. --- NEWS | 4 ++ lang/cpp/src/context.cpp | 68 ++++++++++++++++++++++----------- lang/cpp/src/context.h | 14 +++++++ lang/qt/src/exportjob.h | 2 + lang/qt/src/qgpgmeexportjob.cpp | 19 +++++++-- lang/qt/src/qgpgmeexportjob.h | 5 +++ 6 files changed, 85 insertions(+), 27 deletions(-) diff --git a/NEWS b/NEWS index 0a7816f1..dad97182 100644 --- a/NEWS +++ b/NEWS @@ -30,9 +30,13 @@ Noteworthy changes in version 1.14.0 (unreleased) cpp: UserID::remark NEW. cpp: UserID::remarks NEW. cpp: GpgSignKeyEditInteractor::setDupeOk NEW. + cpp: Context::exportPublicKeys EXTENDED: New param 'flags'. + cpp: Context::startPublicKeyExport EXTENDED: New param 'flags'. + cpp: Context::ExportMode NEW. qt: SignKeyJob::setDupeOk NEW. qt: SignKeyJob::setRemark NEW. qt: GpgCardJob NEW. + qt: ExportJob::setExportFlags NEW. Noteworthy changes in version 1.13.1 (2019-06-13) diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index 002b20f5..2560a338 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -563,44 +563,66 @@ KeyGenerationResult Context::keyGenerationResult() const } } -Error Context::exportPublicKeys(const char *pattern, Data &keyData) +Error Context::exportPublicKeys(const char *pattern, Data &keyData, unsigned int flags) { d->lastop = Private::Export; Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export(d->ctx, pattern, 0, dp ? dp->data : nullptr)); + return Error(d->lasterr = gpgme_op_export(d->ctx, pattern, flags, dp ? dp->data : nullptr)); +} + +Error Context::exportPublicKeys(const char *patterns[], Data &keyData, unsigned int flags) +{ + d->lastop = Private::Export; +#ifndef HAVE_GPGME_EXT_KEYLIST_MODE_EXTERNAL_NONBROKEN + if (!patterns || !patterns[0] || !patterns[1]) { + // max. one pattern -> use the non-ext version + return exportPublicKeys(patterns ? patterns[0] : nullptr, keyData, flags); + } +#endif + Data::Private *const dp = keyData.impl(); + return Error(d->lasterr = gpgme_op_export_ext(d->ctx, patterns, flags, dp ? dp->data : nullptr)); +} + +Error Context::startPublicKeyExport(const char *pattern, Data &keyData, unsigned int flags) +{ + d->lastop = Private::Export; + Data::Private *const dp = keyData.impl(); + return Error(d->lasterr = gpgme_op_export_start(d->ctx, pattern, flags, dp ? dp->data : nullptr)); +} + +Error Context::startPublicKeyExport(const char *patterns[], Data &keyData, unsigned int flags) +{ + d->lastop = Private::Export; +#ifndef HAVE_GPGME_EXT_KEYLIST_MODE_EXTERNAL_NONBROKEN + if (!patterns || !patterns[0] || !patterns[1]) { + // max. one pattern -> use the non-ext version + return startPublicKeyExport(patterns ? patterns[0] : nullptr, keyData, flags); + } +#endif + Data::Private *const dp = keyData.impl(); + return Error(d->lasterr = gpgme_op_export_ext_start(d->ctx, patterns, flags, dp ? dp->data : nullptr)); +} + + +/* Same as above but without flags */ +Error Context::exportPublicKeys(const char *pattern, Data &keyData) +{ + return exportPublicKeys(pattern, keyData, 0); } Error Context::exportPublicKeys(const char *patterns[], Data &keyData) { - d->lastop = Private::Export; -#ifndef HAVE_GPGME_EXT_KEYLIST_MODE_EXTERNAL_NONBROKEN - if (!patterns || !patterns[0] || !patterns[1]) { - // max. one pattern -> use the non-ext version - return exportPublicKeys(patterns ? patterns[0] : nullptr, keyData); - } -#endif - Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_ext(d->ctx, patterns, 0, dp ? dp->data : nullptr)); + return exportPublicKeys(patterns, keyData, 0); } Error Context::startPublicKeyExport(const char *pattern, Data &keyData) { - d->lastop = Private::Export; - Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_start(d->ctx, pattern, 0, dp ? dp->data : nullptr)); + return startPublicKeyExport(pattern, keyData, 0); } Error Context::startPublicKeyExport(const char *patterns[], Data &keyData) { - d->lastop = Private::Export; -#ifndef HAVE_GPGME_EXT_KEYLIST_MODE_EXTERNAL_NONBROKEN - if (!patterns || !patterns[0] || !patterns[1]) { - // max. one pattern -> use the non-ext version - return startPublicKeyExport(patterns ? patterns[0] : nullptr, keyData); - } -#endif - Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_ext_start(d->ctx, patterns, 0, dp ? dp->data : nullptr)); + return startPublicKeyExport(patterns, keyData, 0); } ImportResult Context::importKeys(const Data &data) diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h index b6b902a9..70f1c429 100644 --- a/lang/cpp/src/context.h +++ b/lang/cpp/src/context.h @@ -182,11 +182,25 @@ public: // // Key Export // + enum ExportMode { + ExportDefault = 0, + ExportExtern = 2, + ExportMinimal = 4, + ExportSecret = 16, + ExportRaw = 32, + ExportPKCS12 = 64, + ExportNoUID = 128, + ExportSSH = 256, + }; GpgME::Error exportPublicKeys(const char *pattern, Data &keyData); + GpgME::Error exportPublicKeys(const char *pattern, Data &keyData, unsigned int flags); GpgME::Error exportPublicKeys(const char *pattern[], Data &keyData); + GpgME::Error exportPublicKeys(const char *pattern[], Data &keyData, unsigned int export_mode); GpgME::Error startPublicKeyExport(const char *pattern, Data &keyData); + GpgME::Error startPublicKeyExport(const char *pattern, Data &keyData, unsigned int flags); GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData); + GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData, unsigned int export_mode); // // Key Import diff --git a/lang/qt/src/exportjob.h b/lang/qt/src/exportjob.h index fc1f7ae1..7f79ea08 100644 --- a/lang/qt/src/exportjob.h +++ b/lang/qt/src/exportjob.h @@ -79,6 +79,8 @@ public: */ virtual GpgME::Error start(const QStringList &patterns) = 0; + virtual void setExportFlags (unsigned int flags); + Q_SIGNALS: void result(const GpgME::Error &result, const QByteArray &keyData, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error()); }; diff --git a/lang/qt/src/qgpgmeexportjob.cpp b/lang/qt/src/qgpgmeexportjob.cpp index e2ce1f97..bf3297a7 100644 --- a/lang/qt/src/qgpgmeexportjob.cpp +++ b/lang/qt/src/qgpgmeexportjob.cpp @@ -52,14 +52,15 @@ using namespace QGpgME; using namespace GpgME; QGpgMEExportJob::QGpgMEExportJob(Context *context) - : mixin_type(context) + : mixin_type(context), + m_flags(0) { lateInitialization(); } QGpgMEExportJob::~QGpgMEExportJob() {} -static QGpgMEExportJob::result_type export_qba(Context *ctx, const QStringList &patterns) +static QGpgMEExportJob::result_type export_qba(Context *ctx, const QStringList &patterns, unsigned int flags) { const _detail::PatternConverter pc(patterns); @@ -67,7 +68,7 @@ static QGpgMEExportJob::result_type export_qba(Context *ctx, const QStringList & QGpgME::QByteArrayDataProvider dp; Data data(&dp); - const Error err = ctx->exportPublicKeys(pc.patterns(), data); + const Error err = ctx->exportPublicKeys(pc.patterns(), data, flags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(err, dp.data(), log, ae); @@ -75,7 +76,17 @@ static QGpgMEExportJob::result_type export_qba(Context *ctx, const QStringList & Error QGpgMEExportJob::start(const QStringList &patterns) { - run(std::bind(&export_qba, std::placeholders::_1, patterns)); + run(std::bind(&export_qba, std::placeholders::_1, patterns, m_flags)); return Error(); } + +void QGpgMEExportJob::setExportFlags(unsigned int flags) +{ + m_flags = flags; +} + +/* For ABI compat not pure virtual. */ +void ExportJob::setExportFlags(unsigned int) +{ +} #include "qgpgmeexportjob.moc" diff --git a/lang/qt/src/qgpgmeexportjob.h b/lang/qt/src/qgpgmeexportjob.h index d529feec..3f6bd0e2 100644 --- a/lang/qt/src/qgpgmeexportjob.h +++ b/lang/qt/src/qgpgmeexportjob.h @@ -58,8 +58,13 @@ public: explicit QGpgMEExportJob(GpgME::Context *context); ~QGpgMEExportJob(); + /* from ExportJob */ + void setExportFlags (unsigned int flags) Q_DECL_OVERRIDE; + /* from ExportJob */ GpgME::Error start(const QStringList &patterns) Q_DECL_OVERRIDE; +private: + unsigned int m_flags; }; }