[PATCH] Implement more export-options (clean, no-export-attributes)
Daniele Ricci
daniele.athome at gmail.com
Tue Jan 7 20:35:32 CET 2014
Signed-off-by: Daniele Ricci <daniele.athome at gmail.com>
---
src/engine-gpg.c | 20 ++++++++++++++++++--
src/export.c | 8 ++++++--
src/gpgme.h.in | 2 ++
tests/run-export.c | 26 ++++++++++++++++++++++----
4 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index 2f59bb9..d902d38 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -1754,19 +1754,35 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[],
return err;
}
+// exact length of: --export-options=export-minimal,export-clean,no-export-attributes
+#define EXPORT_OPTIONS_FULL_LEN 65
+// exact length of: --export-options=
+#define EXPORT_OPTIONS_PREFIX_LEN 17
static gpgme_error_t
export_common (engine_gpg_t gpg, gpgme_export_mode_t mode,
gpgme_data_t keydata, int use_armor)
{
gpgme_error_t err = 0;
+ char export_options[EXPORT_OPTIONS_FULL_LEN+1] = "--export-options=";
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
- |GPGME_EXPORT_MODE_MINIMAL)))
+ |GPGME_EXPORT_MODE_MINIMAL
+ |GPGME_EXPORT_MODE_CLEAN
+ |GPGME_EXPORT_MODE_NO_ATTRIBUTES)))
return gpg_error (GPG_ERR_NOT_SUPPORTED);
if ((mode & GPGME_EXPORT_MODE_MINIMAL))
- err = add_arg (gpg, "--export-options=export-minimal");
+ strcat(export_options, "export-minimal,");
+
+ if ((mode & GPGME_EXPORT_MODE_CLEAN))
+ strcat(export_options, "export-clean,");
+
+ if ((mode & GPGME_EXPORT_MODE_NO_ATTRIBUTES))
+ strcat(export_options, "no-export-attributes,");
+
+ if (strlen(export_options) > EXPORT_OPTIONS_PREFIX_LEN)
+ err = add_arg (gpg, export_options);
if (err)
;
diff --git a/src/export.c b/src/export.c
index 81a23b0..9151087 100644
--- a/src/export.c
+++ b/src/export.c
@@ -45,7 +45,9 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
gpgme_error_t err;
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
- |GPGME_EXPORT_MODE_MINIMAL)))
+ |GPGME_EXPORT_MODE_MINIMAL
+ |GPGME_EXPORT_MODE_CLEAN
+ |GPGME_EXPORT_MODE_NO_ATTRIBUTES)))
return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */
@@ -116,7 +118,9 @@ export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[],
gpgme_error_t err;
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
- |GPGME_EXPORT_MODE_MINIMAL)))
+ |GPGME_EXPORT_MODE_MINIMAL
+ |GPGME_EXPORT_MODE_CLEAN
+ |GPGME_EXPORT_MODE_NO_ATTRIBUTES)))
return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */
if ((mode & GPGME_EXPORT_MODE_EXTERN))
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 5c4de6b..551ed60 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -388,6 +388,8 @@ gpgme_pinentry_mode_t;
/* The available export mode flags. */
#define GPGME_EXPORT_MODE_EXTERN 2
#define GPGME_EXPORT_MODE_MINIMAL 4
+#define GPGME_EXPORT_MODE_CLEAN 8
+#define GPGME_EXPORT_MODE_NO_ATTRIBUTES 16
typedef unsigned int gpgme_export_mode_t;
diff --git a/tests/run-export.c b/tests/run-export.c
index 4333208..b0e0771 100644
--- a/tests/run-export.c
+++ b/tests/run-export.c
@@ -43,6 +43,9 @@ show_usage (int ex)
fputs ("usage: " PGM " [options] USERIDS\n\n"
"Options:\n"
" --verbose run in verbose mode\n"
+ " --clean remove any unusable user IDs and signatures\n"
+ " --minimal remove all signatures except self-signatures\n"
+ " --no-attributes do not include any user attribute\n"
" --extern send keys to the keyserver (TAKE CARE!)\n"
, stderr);
exit (ex);
@@ -81,7 +84,22 @@ main (int argc, char **argv)
}
else if (!strcmp (*argv, "--extern"))
{
- mode |= GPGME_KEYLIST_MODE_EXTERN;
+ mode |= GPGME_EXPORT_MODE_EXTERN;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--clean"))
+ {
+ mode |= GPGME_EXPORT_MODE_CLEAN;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--minimal"))
+ {
+ mode |= GPGME_EXPORT_MODE_MINIMAL;
+ argc--; argv++;
+ }
+ else if (!strcmp (*argv, "--no-attributes"))
+ {
+ mode |= GPGME_EXPORT_MODE_NO_ATTRIBUTES;
argc--; argv++;
}
else if (!strncmp (*argv, "--", 2))
@@ -131,7 +149,7 @@ main (int argc, char **argv)
}
/* Now for the actual export. */
- if ((mode & GPGME_KEYLIST_MODE_EXTERN))
+ if ((mode & GPGME_EXPORT_MODE_EXTERN))
printf ("sending keys to keyserver\n");
err = gpgme_data_new (&out);
@@ -139,11 +157,11 @@ main (int argc, char **argv)
gpgme_set_armor (ctx, 1);
err = gpgme_op_export_keys (ctx, keyarray, mode,
- (mode & GPGME_KEYLIST_MODE_EXTERN)? NULL:out);
+ (mode & GPGME_EXPORT_MODE_EXTERN)? NULL:out);
fail_if_err (err);
fflush (NULL);
- if (!(mode & GPGME_KEYLIST_MODE_EXTERN))
+ if (!(mode & GPGME_EXPORT_MODE_EXTERN))
{
fputs ("Begin Result:\n", stdout);
print_data (out);
--
1.8.5.2
More information about the Gnupg-devel
mailing list