From 3658e2df65d321e334a8c96b4d252a4be20354bd Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 27 Mar 2020 19:50:24 +0900 Subject: [PATCH] tests: Add ECC key generation for tests/gpgsm. * tests/gpgsm/t-genkey.c (check_result): New. Signed-off-by: NIIBE Yutaka --- tests/gpgsm/t-genkey.c | 94 ++++++++++++++++++++++++++--------------- tests/gpgsm/t-support.h | 4 ++ 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/tests/gpgsm/t-genkey.c b/tests/gpgsm/t-genkey.c index ac7ef798..e5bbf9cb 100644 --- a/tests/gpgsm/t-genkey.c +++ b/tests/gpgsm/t-genkey.c @@ -59,37 +59,9 @@ progress (void *self, const char *what, int type, int current, int total) } -int -main (void) +static void +check_result (gpgme_genkey_result_t result) { - gpgme_ctx_t ctx; - gpgme_error_t err; - const char *parms = "\n" - "Key-Type: RSA\n" - "Key-Length: 1024\n" - "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n" - "Name-Email: joe@foo.bar\n" - "\n"; - gpgme_genkey_result_t result; - gpgme_data_t certreq; - - init_gpgme (GPGME_PROTOCOL_CMS); - - err = gpgme_data_new (&certreq); - fail_if_err (err); - - err = gpgme_new (&ctx); - fail_if_err (err); - - gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); - gpgme_set_armor (ctx, 1); - - gpgme_set_progress_cb (ctx, progress, NULL); - - err = gpgme_op_genkey (ctx, parms, certreq, NULL); - fail_if_err (err); - - result = gpgme_op_genkey_result (ctx); if (!result) { fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n", @@ -121,10 +93,66 @@ main (void) __FILE__, __LINE__); exit (1); } - gpgme_release (ctx); +} - print_data (certreq); - gpgme_data_release (certreq); +static const char *parms[] = { + "\n" + "Key-Type: RSA\n" + "Key-Length: 1024\n" + "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n" + "Name-Email: joe@foo.bar\n" + "\n", + "\n" + "Key-Type: ECC\n" + "Key-Curve: NIST P-256\n" + "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n" + "Name-Email: joe@foo.bar\n" + "\n", + "\n" + "Key-Type: ECC\n" + "Key-Curve: Ed25519\n" + "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n" + "Name-Email: joe@foo.bar\n" + "\n", +}; + +int +main (void) +{ + gpgme_ctx_t ctx; + gpgme_error_t err; + gpgme_genkey_result_t result; + int i; + + init_gpgme (GPGME_PROTOCOL_CMS); + + err = gpgme_new (&ctx); + fail_if_err (err); + + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + gpgme_set_armor (ctx, 1); + + gpgme_set_progress_cb (ctx, progress, NULL); + + for (i = 0; i < DIM(parms); i++) + { + gpgme_data_t certreq; + + progress_called = 0; + err = gpgme_data_new (&certreq); + fail_if_err (err); + + err = gpgme_op_genkey (ctx, parms[i], certreq, NULL); + fail_if_err (err); + + result = gpgme_op_genkey_result (ctx); + check_result (result); + + print_data (certreq); + gpgme_data_release (certreq); + } + + gpgme_release (ctx); return 0; } diff --git a/tests/gpgsm/t-support.h b/tests/gpgsm/t-support.h index a0066599..fe65364f 100644 --- a/tests/gpgsm/t-support.h +++ b/tests/gpgsm/t-support.h @@ -26,6 +26,10 @@ #include +#ifndef DIM +#define DIM(v) (sizeof(v)/sizeof((v)[0])) +#endif + #define fail_if_err(err) \ do \ { \