From f952226043824cbbeb8517126b5266926121c4e8 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 2 Apr 2019 18:49:51 +0200 Subject: [PATCH] common: Extend function pubkey_algo_string. * common/sexputil.c (pubkey_algo_string): Add arg R_ALGOID. * sm/certreqgen-ui.c (gpgsm_gencertreq_tty): Adjust. * tools/gpg-card.c (list_one_kinfo): Ditto. Signed-off-by: Werner Koch --- common/sexputil.c | 9 +++++++-- common/util.h | 2 +- sm/certreqgen-ui.c | 2 +- tools/gpg-card.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/sexputil.c b/common/sexputil.c index d3020e169..f99bc3b18 100644 --- a/common/sexputil.c +++ b/common/sexputil.c @@ -581,9 +581,9 @@ get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen) /* Given the public key S_PKEY, return a new buffer with a descriptive * string for its algorithm. This function may return NULL on memory - * error. */ + * error. If R_ALGOID is not NULL the gcrypt algo id is stored there. */ char * -pubkey_algo_string (gcry_sexp_t s_pkey) +pubkey_algo_string (gcry_sexp_t s_pkey, enum gcry_pk_algos *r_algoid) { const char *prefix; gcry_sexp_t l1; @@ -591,6 +591,9 @@ pubkey_algo_string (gcry_sexp_t s_pkey) int algo; char *result; + if (r_algoid) + *r_algoid = 0; + l1 = gcry_sexp_find_token (s_pkey, "public-key", 0); if (!l1) return xtrystrdup ("E_no_key"); @@ -632,6 +635,8 @@ pubkey_algo_string (gcry_sexp_t s_pkey) else result = xtryasprintf ("X_algo_%d", algo); + if (r_algoid) + *r_algoid = algo; xfree (algoname); return result; } diff --git a/common/util.h b/common/util.h index 8895137ec..bd6cd1ff5 100644 --- a/common/util.h +++ b/common/util.h @@ -192,7 +192,7 @@ gpg_error_t get_rsa_pk_from_canon_sexp (const unsigned char *keydata, int get_pk_algo_from_key (gcry_sexp_t key); int get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen); -char *pubkey_algo_string (gcry_sexp_t s_pkey); +char *pubkey_algo_string (gcry_sexp_t s_pkey, enum gcry_pk_algos *r_algoid); /*-- convert.c --*/ int hex2bin (const char *string, void *buffer, size_t length); diff --git a/sm/certreqgen-ui.c b/sm/certreqgen-ui.c index 6f822bdbc..ae9ec35d0 100644 --- a/sm/certreqgen-ui.c +++ b/sm/certreqgen-ui.c @@ -258,7 +258,7 @@ gpgsm_gencertreq_tty (ctrl_t ctrl, estream_t output_stream) if (!gpgsm_agent_readkey (ctrl, 1, keyref, &pkey)) { if (!gcry_sexp_new (&s_pkey, pkey, 0, 0)) - algostr = pubkey_algo_string (s_pkey); + algostr = pubkey_algo_string (s_pkey, NULL); gcry_sexp_release (s_pkey); } xfree (pkey); diff --git a/tools/gpg-card.c b/tools/gpg-card.c index 7b3f8a3f6..d98a545ff 100644 --- a/tools/gpg-card.c +++ b/tools/gpg-card.c @@ -673,7 +673,7 @@ list_one_kinfo (key_info_t firstkinfo, key_info_t kinfo, if (!scd_readkey (kinfo->keyref, &s_pkey)) { - char *tmp = pubkey_algo_string (s_pkey); + char *tmp = pubkey_algo_string (s_pkey, NULL); tty_fprintf (fp, " algorithm ..: %s\n", tmp); xfree (tmp); gcry_sexp_release (s_pkey);