From 60880adafa93e1a1e8e9fecf03c14d56bbd55345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 13 Dec 2021 16:52:23 +0100 Subject: core: Allow specifiying a key origin when importing keys * src/context.h (struct gpgme_context): New field key_origin. * src/engine-backend.h (struct engine_ops): Add arg key_origin to field 'import'. * src/engine-gpg.c (gpg_import): Add arg key_origin and pass option --key-origin with argument value to gpg. Adjust all callers. * src/engine-gpgsm.c (gpgsm_import): Add dummy arg key_origin. * src/gpgme.c (gpgme_release): Free 'key_origin'. (gpgme_set_ctx_flag, gpgme_get_ctx_flag): New flag "key-origin". * tests/run-import.c (main): Add option --key-origin. * tests/gpg/t-import.c (main): Set and verify key origin. -- This makes the --key-origin option available in the GPGME API for key imports. GnuPG-bug-id: 5733 --- tests/run-import.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/run-import.c') diff --git a/tests/run-import.c b/tests/run-import.c index 36d9a0d5..0ddf158d 100644 --- a/tests/run-import.c +++ b/tests/run-import.c @@ -46,6 +46,7 @@ show_usage (int ex) " --verbose run in verbose mode\n" " --openpgp use the OpenPGP protocol (default)\n" " --cms use the CMS protocol\n" + " --key-origin use the specified key origin\n" " --url import from given URLs\n" " -0 URLs are delimited by a nul\n" , stderr); @@ -63,6 +64,7 @@ main (int argc, char **argv) gpgme_import_result_t impres; gpgme_data_t data; gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; + char *key_origin = NULL; if (argc) { argc--; argv++; } @@ -101,6 +103,14 @@ main (int argc, char **argv) protocol = GPGME_PROTOCOL_CMS; argc--; argv++; } + else if (!strcmp (*argv, "--key-origin")) + { + argc--; argv++; + if (!argc) + show_usage (1); + key_origin = strdup (*argv); + argc--; argv++; + } else if (!strncmp (*argv, "--", 2)) show_usage (1); @@ -115,6 +125,12 @@ main (int argc, char **argv) fail_if_err (err); gpgme_set_protocol (ctx, protocol); + if (key_origin) + { + err = gpgme_set_ctx_flag (ctx, "key-origin", key_origin); + fail_if_err (err); + } + for (; argc; argc--, argv++) { printf ("reading file `%s'\n", *argv); -- cgit v1.2.3