mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
gpg: Unify the the use of the print_pubkey_info functions.
* g10/keylist.c (format_seckey_info): Remove. (print_pubkey_info, print_seckey_info): Remove. (format_key_info): New. (print_key_info): New. (print_key_info_log): New. * g10/card-util.c (current_card_status): Use print_key_info and remove the useless condition on KEYBLOCK. * g10/delkey.c (do_delete_key): Replace print_pubkey_info and print_seckey_info by print_key_info. * g10/keyedit.c (menu_addrevoker): Replace print_pubkey_info by print_key_info. * g10/pkclist.c (do_we_trust_pre): Ditto. * g10/revoke.c (gen_desig_revoke): Ditto. (gen_revoke): Ditto. Also use print_key_info_log instead of separate functions. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
1eb93d9229
commit
126caa34bb
7 changed files with 75 additions and 64 deletions
|
@ -165,43 +165,15 @@ secret_key_list (ctrl_t ctrl, strlist_t list)
|
|||
list_one (ctrl, list, 1, 0);
|
||||
}
|
||||
|
||||
char *
|
||||
format_seckey_info (ctrl_t ctrl, PKT_public_key *pk)
|
||||
{
|
||||
u32 keyid[2];
|
||||
char *p;
|
||||
char pkstrbuf[PUBKEY_STRING_SIZE];
|
||||
char *info;
|
||||
|
||||
keyid_from_pk (pk, keyid);
|
||||
p = get_user_id_native (ctrl, keyid);
|
||||
|
||||
info = xtryasprintf ("sec %s/%s %s %s",
|
||||
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
|
||||
keystr (keyid), datestr_from_pk (pk), p);
|
||||
|
||||
xfree (p);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
void
|
||||
print_seckey_info (ctrl_t ctrl, PKT_public_key *pk)
|
||||
{
|
||||
char *p = format_seckey_info (ctrl, pk);
|
||||
tty_printf ("\n%s\n", p);
|
||||
xfree (p);
|
||||
}
|
||||
|
||||
/* Print information about the public key. With FP passed as NULL,
|
||||
the tty output interface is used, otherwise output is directed to
|
||||
the given stream. */
|
||||
void
|
||||
print_pubkey_info (ctrl_t ctrl, estream_t fp, PKT_public_key *pk)
|
||||
|
||||
/* Helper for print_key_info and print_key_info_log. */
|
||||
static char *
|
||||
format_key_info (ctrl_t ctrl, PKT_public_key *pk, int secret)
|
||||
{
|
||||
u32 keyid[2];
|
||||
char *p;
|
||||
char pkstrbuf[PUBKEY_STRING_SIZE];
|
||||
char *result;
|
||||
|
||||
keyid_from_pk (pk, keyid);
|
||||
|
||||
|
@ -212,13 +184,59 @@ print_pubkey_info (ctrl_t ctrl, estream_t fp, PKT_public_key *pk)
|
|||
else
|
||||
p = get_user_id_native (ctrl, keyid);
|
||||
|
||||
if (!fp)
|
||||
tty_printf ("\n");
|
||||
tty_fprintf (fp, "%s %s/%s %s %s\n",
|
||||
pk->flags.primary? "pub":"sub",
|
||||
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
|
||||
keystr (keyid), datestr_from_pk (pk), p);
|
||||
result = xtryasprintf ("%s %s/%s %s %s",
|
||||
secret? (pk->flags.primary? "sec":"ssb")
|
||||
/* */ : (pk->flags.primary? "pub":"sub"),
|
||||
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
|
||||
keystr (keyid), datestr_from_pk (pk), p);
|
||||
xfree (p);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Print basic information about a public or secret key. With FP
|
||||
* passed as NULL, the tty output interface is used, otherwise output
|
||||
* is directed to the given stream. INDENT gives the requested
|
||||
* indentation; if that is a negative value indentation is suppressed
|
||||
* for the first line. SECRET tells that the PK has a secret part.
|
||||
* FIXME: This is similar in use to print_key_line and thus both
|
||||
* functions should eventually be united.
|
||||
*/
|
||||
void
|
||||
print_key_info (ctrl_t ctrl, estream_t fp,
|
||||
int indent, PKT_public_key *pk, int secret)
|
||||
{
|
||||
int indentabs = indent >= 0? indent : -indent;
|
||||
char *info;
|
||||
|
||||
/* Note: Negative values for INDENT are not yet needed. */
|
||||
|
||||
info = format_key_info (ctrl, pk, secret);
|
||||
|
||||
if (!fp && indent >= 0)
|
||||
tty_printf ("\n"); /* (Backward compatibility to old code) */
|
||||
tty_fprintf (fp, "%*s%s\n", indentabs, "",
|
||||
info? info : "[Ooops - out of core]");
|
||||
|
||||
xfree (info);
|
||||
}
|
||||
|
||||
|
||||
/* Same as print_key_info put print using the log functions at
|
||||
* LOGLEVEL. */
|
||||
void
|
||||
print_key_info_log (ctrl_t ctrl, int loglevel,
|
||||
int indent, PKT_public_key *pk, int secret)
|
||||
{
|
||||
int indentabs = indent >= 0? indent : -indent;
|
||||
char *info;
|
||||
|
||||
info = format_key_info (ctrl, pk, secret);
|
||||
|
||||
log_log (loglevel, "%*s%s\n", indentabs, "",
|
||||
info? info : "[Ooops - out of core]");
|
||||
|
||||
xfree (info);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue