diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index d01f9453..174a3c3b 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -582,36 +582,67 @@ KeyGenerationResult Context::keyGenerationResult() const } } -Error Context::exportPublicKeys(const char *pattern, Data &keyData, unsigned int flags) +Error Context::exportKeys(const char *pattern, Data &keyData, unsigned int mode) { d->lastop = Private::Export; Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export(d->ctx, pattern, flags, dp ? dp->data : nullptr)); + return Error(d->lasterr = gpgme_op_export(d->ctx, pattern, mode, dp ? dp->data : nullptr)); } -Error Context::exportPublicKeys(const char *patterns[], Data &keyData, unsigned int flags) +Error Context::exportKeys(const char *patterns[], Data &keyData, unsigned int mode) { d->lastop = Private::Export; Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_ext(d->ctx, patterns, flags, dp ? dp->data : nullptr)); + return Error(d->lasterr = gpgme_op_export_ext(d->ctx, patterns, mode, dp ? dp->data : nullptr)); } -Error Context::startPublicKeyExport(const char *pattern, Data &keyData, unsigned int flags) +Error Context::startKeyExport(const char *pattern, Data &keyData, unsigned int mode) { 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)); + return Error(d->lasterr = gpgme_op_export_start(d->ctx, pattern, mode, dp ? dp->data : nullptr)); } -Error Context::startPublicKeyExport(const char *patterns[], Data &keyData, unsigned int flags) +Error Context::startKeyExport(const char *patterns[], Data &keyData, unsigned int mode) { d->lastop = Private::Export; Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_ext_start(d->ctx, patterns, flags, dp ? dp->data : nullptr)); + return Error(d->lasterr = gpgme_op_export_ext_start(d->ctx, patterns, mode, dp ? dp->data : nullptr)); } +Error Context::exportPublicKeys(const char *pattern, Data &keyData, unsigned int mode) +{ + if (mode & ExportSecret) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return exportKeys(pattern, keyData, mode); +} -/* Same as above but without flags */ +Error Context::exportPublicKeys(const char *patterns[], Data &keyData, unsigned int mode) +{ + if (mode & ExportSecret) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return exportKeys(patterns, keyData, mode); +} + +Error Context::startPublicKeyExport(const char *pattern, Data &keyData, unsigned int mode) +{ + if (mode & ExportSecret) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return startKeyExport(pattern, keyData, mode); +} + +Error Context::startPublicKeyExport(const char *patterns[], Data &keyData, unsigned int mode) +{ + if (mode & ExportSecret) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return startKeyExport(patterns, keyData, mode); +} + +/* Same as above but without mode */ Error Context::exportPublicKeys(const char *pattern, Data &keyData) { return exportPublicKeys(pattern, keyData, 0); @@ -632,6 +663,38 @@ Error Context::startPublicKeyExport(const char *patterns[], Data &keyData) return startPublicKeyExport(patterns, keyData, 0); } +Error Context::exportSecretKeys(const char *pattern, Data &keyData, unsigned int mode) +{ + if (mode & ExportSecretSubkey) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return exportKeys(pattern, keyData, mode|ExportSecret); +} + +Error Context::exportSecretKeys(const char *patterns[], Data &keyData, unsigned int mode) +{ + if (mode & ExportSecretSubkey) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return exportKeys(patterns, keyData, mode|ExportSecret); +} + +Error Context::startSecretKeyExport(const char *pattern, Data &keyData, unsigned int mode) +{ + if (mode & ExportSecretSubkey) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return startKeyExport(pattern, keyData, mode|ExportSecret); +} + +Error Context::startSecretKeyExport(const char *patterns[], Data &keyData, unsigned int mode) +{ + if (mode & ExportSecretSubkey) { + return Error::fromCode(GPG_ERR_INV_FLAG); + } + return startKeyExport(patterns, keyData, mode|ExportSecret); +} + ImportResult Context::importKeys(const Data &data) { d->lastop = Private::Import; diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h index 430c16e9..2631678a 100644 --- a/lang/cpp/src/context.h +++ b/lang/cpp/src/context.h @@ -194,13 +194,24 @@ public: }; 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, unsigned int mode); GpgME::Error exportPublicKeys(const char *pattern[], Data &keyData); - GpgME::Error exportPublicKeys(const char *pattern[], Data &keyData, unsigned int export_mode); + GpgME::Error exportPublicKeys(const char *pattern[], Data &keyData, unsigned int 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, unsigned int mode); GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData); - GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData, unsigned int export_mode); + GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData, unsigned int mode); + + GpgME::Error exportSecretKeys(const char *pattern, Data &keyData, unsigned int mode = ExportSecret); + GpgME::Error exportSecretKeys(const char *pattern[], Data &keyData, unsigned int mode = ExportSecret); + GpgME::Error startSecretKeyExport(const char *pattern, Data &keyData, unsigned int mode = ExportSecret); + GpgME::Error startSecretKeyExport(const char *pattern[], Data &keyData, unsigned int mode = ExportSecret); + + // generic export functions; prefer using the specific public/secret key export functions + GpgME::Error exportKeys(const char *pattern, Data &keyData, unsigned int mode = ExportDefault); + GpgME::Error exportKeys(const char *pattern[], Data &keyData, unsigned int mode = ExportDefault); + GpgME::Error startKeyExport(const char *pattern, Data &keyData, unsigned int mode = ExportDefault); + GpgME::Error startKeyExport(const char *pattern[], Data &keyData, unsigned int mode = ExportDefault); // // Key Import