diff options
Diffstat (limited to 'scd/app-help.c')
-rw-r--r-- | scd/app-help.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/scd/app-help.c b/scd/app-help.c index f95928675..8d225ef58 100644 --- a/scd/app-help.c +++ b/scd/app-help.c @@ -57,10 +57,13 @@ app_help_count_bits (const unsigned char *a, size_t len) * function succeeded, the S-expression representing the key is stored * there. The caller needs to call gcry_sexp_release on that. If * R_ALGO is not NULL the public key algorithm id of Libgcrypt is - * stored there. */ + * stored there. If R_ALGOSTR is not NULL and the function succeeds a + * newly allocated algo string (e.g. "rsa2048") is stored there. + * HEXKEYGRIP may be NULL if the caller is not interested in it. */ gpg_error_t app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip, - gcry_sexp_t *r_pkey, int *r_algo) + gcry_sexp_t *r_pkey, int *r_algo, + char **r_algostr) { gpg_error_t err; gcry_sexp_t s_pkey; @@ -68,11 +71,13 @@ app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip, if (r_pkey) *r_pkey = NULL; + if (r_algostr) + *r_algostr = NULL; err = gcry_sexp_sscan (&s_pkey, NULL, pk, pklen); if (err) return err; /* Can't parse that S-expression. */ - if (!gcry_pk_get_keygrip (s_pkey, array)) + if (hexkeygrip && !gcry_pk_get_keygrip (s_pkey, array)) { gcry_sexp_release (s_pkey); return gpg_error (GPG_ERR_GENERAL); /* Failed to calculate the keygrip.*/ @@ -81,12 +86,24 @@ app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip, if (r_algo) *r_algo = get_pk_algo_from_key (s_pkey); + if (r_algostr) + { + *r_algostr = pubkey_algo_string (s_pkey, NULL); + if (!*r_algostr) + { + err = gpg_error_from_syserror (); + gcry_sexp_release (s_pkey); + return err; + } + } + if (r_pkey) *r_pkey = s_pkey; else gcry_sexp_release (s_pkey); - bin2hex (array, KEYGRIP_LEN, hexkeygrip); + if (hexkeygrip) + bin2hex (array, KEYGRIP_LEN, hexkeygrip); return 0; } @@ -116,7 +133,7 @@ app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip, if (!n) return gpg_error (GPG_ERR_INV_SEXP); err = app_help_get_keygrip_string_pk ((void*)p, n, hexkeygrip, - r_pkey, r_algo); + r_pkey, r_algo, NULL); ksba_free (p); return err; } |