summaryrefslogtreecommitdiff
path: root/src/export.c
diff options
context:
space:
mode:
authorIngo Klöcker <dev@ingo-kloecker.de>2022-01-03 14:41:19 +0100
committerIngo Klöcker <dev@ingo-kloecker.de>2022-01-04 09:21:37 +0100
commit326857511587fa7878757d3884f91bf7eb86771c (patch)
treed1d6f5f09ea409991d1232649b316b88208fadaa /src/export.c
parent82f43455e9412d8b4792b35371e0b6704a619d07 (diff)
downloadgpgme-326857511587fa7878757d3884f91bf7eb86771c.tar.gz
core: Factor out the check for valid export mode flags.
* src/export.c (check_mode): New. (export_start, export_ext_start): Call check_mode. -- GnuPG-bug-id: 5757
Diffstat (limited to 'src/export.c')
-rw-r--r--src/export.c60
1 files changed, 22 insertions, 38 deletions
diff --git a/src/export.c b/src/export.c
index 4cee0ef9..c07433b0 100644
--- a/src/export.c
+++ b/src/export.c
@@ -117,13 +117,9 @@ export_status_handler (void *priv, gpgme_status_code_t code, char *args)
static gpgme_error_t
-export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
- gpgme_export_mode_t mode, gpgme_data_t keydata)
+check_mode (gpgme_export_mode_t mode, gpgme_protocol_t protocol,
+ gpgme_data_t keydata)
{
- gpgme_error_t err;
- void *hook;
- op_data_t opd;
-
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
|GPGME_EXPORT_MODE_MINIMAL
|GPGME_EXPORT_MODE_SECRET
@@ -140,7 +136,7 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
&& (mode & GPGME_EXPORT_MODE_PKCS12))
return gpg_error (GPG_ERR_INV_FLAG); /* Combination not allowed. */
- if (ctx->protocol != GPGME_PROTOCOL_CMS
+ if (protocol != GPGME_PROTOCOL_CMS
&& (mode & (GPGME_EXPORT_MODE_RAW|GPGME_EXPORT_MODE_PKCS12)))
return gpg_error (GPG_ERR_INV_FLAG); /* Only supported for X.509. */
}
@@ -156,6 +152,22 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
return gpg_error (GPG_ERR_INV_VALUE);
}
+ return 0;
+}
+
+
+static gpgme_error_t
+export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
+ gpgme_export_mode_t mode, gpgme_data_t keydata)
+{
+ gpgme_error_t err;
+ void *hook;
+ op_data_t opd;
+
+ err = check_mode (mode, ctx->protocol, keydata);
+ if (err)
+ return err;
+
err = _gpgme_op_reset (ctx, synchronous);
if (err)
return err;
@@ -227,37 +239,9 @@ export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[],
void *hook;
op_data_t opd;
- if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
- |GPGME_EXPORT_MODE_MINIMAL
- |GPGME_EXPORT_MODE_SECRET
- |GPGME_EXPORT_MODE_SSH
- |GPGME_EXPORT_MODE_RAW
- |GPGME_EXPORT_MODE_PKCS12)))
- return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */
-
- if ((mode & GPGME_EXPORT_MODE_SECRET))
- {
- if ((mode & GPGME_EXPORT_MODE_EXTERN))
- return gpg_error (GPG_ERR_INV_FLAG); /* Combination not allowed. */
- if ((mode & GPGME_EXPORT_MODE_RAW)
- && (mode & GPGME_EXPORT_MODE_PKCS12))
- return gpg_error (GPG_ERR_INV_FLAG); /* Combination not allowed. */
-
- if (ctx->protocol != GPGME_PROTOCOL_CMS
- && (mode & (GPGME_EXPORT_MODE_RAW|GPGME_EXPORT_MODE_PKCS12)))
- return gpg_error (GPG_ERR_INV_FLAG); /* Only supported for X.509. */
- }
-
- if ((mode & GPGME_EXPORT_MODE_EXTERN))
- {
- if (keydata)
- return gpg_error (GPG_ERR_INV_VALUE);
- }
- else
- {
- if (!keydata)
- return gpg_error (GPG_ERR_INV_VALUE);
- }
+ err = check_mode (mode, ctx->protocol, keydata);
+ if (err)
+ return err;
err = _gpgme_op_reset (ctx, synchronous);
if (err)