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.
This commit is contained in:
Andre Heinecke 2020-07-16 17:00:28 +02:00
parent dfeedcc28d
commit 690d967196
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C
6 changed files with 85 additions and 27 deletions

4
NEWS
View File

@ -30,9 +30,13 @@ Noteworthy changes in version 1.14.0 (unreleased)
cpp: UserID::remark NEW. cpp: UserID::remark NEW.
cpp: UserID::remarks NEW. cpp: UserID::remarks NEW.
cpp: GpgSignKeyEditInteractor::setDupeOk 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::setDupeOk NEW.
qt: SignKeyJob::setRemark NEW. qt: SignKeyJob::setRemark NEW.
qt: GpgCardJob NEW. qt: GpgCardJob NEW.
qt: ExportJob::setExportFlags NEW.
Noteworthy changes in version 1.13.1 (2019-06-13) Noteworthy changes in version 1.13.1 (2019-06-13)

View File

@ -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; d->lastop = Private::Export;
Data::Private *const dp = keyData.impl(); 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) Error Context::exportPublicKeys(const char *patterns[], Data &keyData)
{ {
d->lastop = Private::Export; return exportPublicKeys(patterns, keyData, 0);
#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));
} }
Error Context::startPublicKeyExport(const char *pattern, Data &keyData) Error Context::startPublicKeyExport(const char *pattern, Data &keyData)
{ {
d->lastop = Private::Export; return startPublicKeyExport(pattern, keyData, 0);
Data::Private *const dp = keyData.impl();
return Error(d->lasterr = gpgme_op_export_start(d->ctx, pattern, 0, dp ? dp->data : nullptr));
} }
Error Context::startPublicKeyExport(const char *patterns[], Data &keyData) Error Context::startPublicKeyExport(const char *patterns[], Data &keyData)
{ {
d->lastop = Private::Export; return startPublicKeyExport(patterns, keyData, 0);
#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));
} }
ImportResult Context::importKeys(const Data &data) ImportResult Context::importKeys(const Data &data)

View File

@ -182,11 +182,25 @@ public:
// //
// Key Export // 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);
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);
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);
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);
GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData, unsigned int export_mode);
// //
// Key Import // Key Import

View File

@ -79,6 +79,8 @@ public:
*/ */
virtual GpgME::Error start(const QStringList &patterns) = 0; virtual GpgME::Error start(const QStringList &patterns) = 0;
virtual void setExportFlags (unsigned int flags);
Q_SIGNALS: Q_SIGNALS:
void result(const GpgME::Error &result, const QByteArray &keyData, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error()); void result(const GpgME::Error &result, const QByteArray &keyData, const QString &auditLogAsHtml = QString(), const GpgME::Error &auditLogError = GpgME::Error());
}; };

View File

@ -52,14 +52,15 @@ using namespace QGpgME;
using namespace GpgME; using namespace GpgME;
QGpgMEExportJob::QGpgMEExportJob(Context *context) QGpgMEExportJob::QGpgMEExportJob(Context *context)
: mixin_type(context) : mixin_type(context),
m_flags(0)
{ {
lateInitialization(); lateInitialization();
} }
QGpgMEExportJob::~QGpgMEExportJob() {} 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); const _detail::PatternConverter pc(patterns);
@ -67,7 +68,7 @@ static QGpgMEExportJob::result_type export_qba(Context *ctx, const QStringList &
QGpgME::QByteArrayDataProvider dp; QGpgME::QByteArrayDataProvider dp;
Data data(&dp); Data data(&dp);
const Error err = ctx->exportPublicKeys(pc.patterns(), data); const Error err = ctx->exportPublicKeys(pc.patterns(), data, flags);
Error ae; Error ae;
const QString log = _detail::audit_log_as_html(ctx, ae); const QString log = _detail::audit_log_as_html(ctx, ae);
return std::make_tuple(err, dp.data(), log, 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) 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(); 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" #include "qgpgmeexportjob.moc"

View File

@ -58,8 +58,13 @@ public:
explicit QGpgMEExportJob(GpgME::Context *context); explicit QGpgMEExportJob(GpgME::Context *context);
~QGpgMEExportJob(); ~QGpgMEExportJob();
/* from ExportJob */
void setExportFlags (unsigned int flags) Q_DECL_OVERRIDE;
/* from ExportJob */ /* from ExportJob */
GpgME::Error start(const QStringList &patterns) Q_DECL_OVERRIDE; GpgME::Error start(const QStringList &patterns) Q_DECL_OVERRIDE;
private:
unsigned int m_flags;
}; };
} }