diff options
author | Werner Koch <[email protected]> | 2019-02-26 15:42:50 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2019-02-26 16:01:46 +0000 |
commit | c2235d994dbb1d7ddba20f89a7c02f4a27b0610c (patch) | |
tree | 655f49c9a3436d6047f30234c7b85c36bbe18a21 /scd/app-help.c | |
parent | conf: New option --show-socket. (diff) | |
download | gnupg-c2235d994dbb1d7ddba20f89a7c02f4a27b0610c.tar.gz gnupg-c2235d994dbb1d7ddba20f89a7c02f4a27b0610c.zip |
scd: Simplify the app_readkey parameters.
* scd/app-help.c (app_help_pubkey_from_cert): New.
* scd/command.c (cmd_readkey): Refactor to use that new function and
handle the --advanced flag only here.
* scd/app.c (app_readkey): Remove parm advanced.
* scd/app-common.h (struct app_ctx_s): Remove parm advanced from the
readkey member.
* scd/app-nks.c (do_readkey): Adjust for removed parm.
* scd/app-piv.c (do_readkey): Ditto.
* scd/app-openpgp.c (do_readkey): Ditto.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'scd/app-help.c')
-rw-r--r-- | scd/app-help.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/scd/app-help.c b/scd/app-help.c index 842a73d5a..f0f551c55 100644 --- a/scd/app-help.c +++ b/scd/app-help.c @@ -29,9 +29,9 @@ #include "../common/tlv.h" -/* Count the number of bits, assuming the A represents an unsigned big - integer of length LEN bytes. If A is NULL a length of 0 is - returned. */ +/* Count the number of bits, assuming that A represents an unsigned + * big integer of length LEN bytes. If A is NULL a length of 0 is + * returned. */ unsigned int app_help_count_bits (const unsigned char *a, size_t len) { @@ -87,6 +87,45 @@ app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip) } +gpg_error_t +app_help_pubkey_from_cert (const void *cert, size_t certlen, + unsigned char **r_pk, size_t *r_pklen) +{ + gpg_error_t err; + ksba_cert_t kc; + unsigned char *pk; + size_t pklen; + + *r_pk = NULL; + *r_pklen = 0; + + err = ksba_cert_new (&kc); + if (err) + return err; + + err = ksba_cert_init_from_mem (kc, cert, certlen); + if (err) + goto leave; + + pk = ksba_cert_get_public_key (kc); + if (!pk) + { + err = gpg_error (GPG_ERR_NO_PUBKEY); + goto leave; + } + pklen = gcry_sexp_canon_len (pk, 0, NULL, &err); + + leave: + if (!err) + { + *r_pk = pk; + *r_pklen = pklen; + } + else + ksba_free (pk); + ksba_cert_release (kc); + return err; +} /* Given the SLOT and the File ID FID, return the length of the certificate contained in that file. Returns 0 if the file does not |