1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-26 01:52:45 +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:
Werner Koch 2019-05-21 12:54:47 +02:00
parent 1eb93d9229
commit 126caa34bb
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
7 changed files with 75 additions and 64 deletions

View File

@ -680,9 +680,8 @@ current_card_status (ctrl_t ctrl, estream_t fp,
if ( thefpr && !fpr_is_ff (thefpr, thefprlen) if ( thefpr && !fpr_is_ff (thefpr, thefprlen)
&& !get_pubkey_byfprint (ctrl, pk, &keyblock, thefpr, thefprlen)) && !get_pubkey_byfprint (ctrl, pk, &keyblock, thefpr, thefprlen))
{ {
print_pubkey_info (ctrl, fp, pk); print_key_info (ctrl, fp, 0, pk, 0);
if (keyblock) print_card_key_info (fp, keyblock);
print_card_key_info (fp, keyblock);
} }
else else
tty_fprintf (fp, "[none]\n"); tty_fprintf (fp, "[none]\n");

View File

@ -135,10 +135,7 @@ do_delete_key (ctrl_t ctrl, const char *username, int secret, int force,
} }
else else
{ {
if (secret) print_key_info (ctrl, NULL, 0, pk, secret);
print_seckey_info (ctrl, pk);
else
print_pubkey_info (ctrl, NULL, pk );
tty_printf( "\n" ); tty_printf( "\n" );
yes = cpr_get_answer_is_yes yes = cpr_get_answer_is_yes

View File

@ -4356,7 +4356,7 @@ menu_addrevoker (ctrl_t ctrl, kbnode_t pub_keyblock, int sensitive)
continue; continue;
} }
print_pubkey_info (ctrl, NULL, revoker_pk); print_key_info (ctrl, NULL, 0, revoker_pk, 0);
print_fingerprint (ctrl, NULL, revoker_pk, 2); print_fingerprint (ctrl, NULL, revoker_pk, 2);
tty_printf ("\n"); tty_printf ("\n");

View File

@ -165,43 +165,15 @@ secret_key_list (ctrl_t ctrl, strlist_t list)
list_one (ctrl, list, 1, 0); list_one (ctrl, list, 1, 0);
} }
char *
format_seckey_info (ctrl_t ctrl, PKT_public_key *pk) /* Helper for print_key_info and print_key_info_log. */
{ static char *
u32 keyid[2]; format_key_info (ctrl_t ctrl, PKT_public_key *pk, int secret)
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)
{ {
u32 keyid[2]; u32 keyid[2];
char *p; char *p;
char pkstrbuf[PUBKEY_STRING_SIZE]; char pkstrbuf[PUBKEY_STRING_SIZE];
char *result;
keyid_from_pk (pk, keyid); keyid_from_pk (pk, keyid);
@ -212,13 +184,59 @@ print_pubkey_info (ctrl_t ctrl, estream_t fp, PKT_public_key *pk)
else else
p = get_user_id_native (ctrl, keyid); p = get_user_id_native (ctrl, keyid);
if (!fp) result = xtryasprintf ("%s %s/%s %s %s",
tty_printf ("\n"); secret? (pk->flags.primary? "sec":"ssb")
tty_fprintf (fp, "%s %s/%s %s %s\n", /* */ : (pk->flags.primary? "pub":"sub"),
pk->flags.primary? "pub":"sub", pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf), keystr (keyid), datestr_from_pk (pk), p);
keystr (keyid), datestr_from_pk (pk), p);
xfree (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);
} }

View File

@ -470,9 +470,10 @@ void show_keyserver_url(PKT_signature *sig,int indent,int mode);
void show_notation(PKT_signature *sig,int indent,int mode,int which); void show_notation(PKT_signature *sig,int indent,int mode,int which);
void dump_attribs (const PKT_user_id *uid, PKT_public_key *pk); void dump_attribs (const PKT_user_id *uid, PKT_public_key *pk);
void set_attrib_fd(int fd); void set_attrib_fd(int fd);
char *format_seckey_info (ctrl_t ctrl, PKT_public_key *pk); void print_key_info (ctrl_t ctrl, estream_t fp, int indent,
void print_seckey_info (ctrl_t ctrl, PKT_public_key *pk); PKT_public_key *pk, int secret);
void print_pubkey_info (ctrl_t ctrl, estream_t fp, PKT_public_key *pk); void print_key_info_log (ctrl_t ctrl, int loglevel, int indent,
PKT_public_key *pk, int secret);
void print_card_key_info (estream_t fp, KBNODE keyblock); void print_card_key_info (estream_t fp, KBNODE keyblock);
void print_key_line (ctrl_t ctrl, estream_t fp, PKT_public_key *pk, int secret); void print_key_line (ctrl_t ctrl, estream_t fp, PKT_public_key *pk, int secret);

View File

@ -475,7 +475,7 @@ do_we_trust_pre (ctrl_t ctrl, PKT_public_key *pk, unsigned int trustlevel )
if( !opt.batch && !rc ) if( !opt.batch && !rc )
{ {
print_pubkey_info (ctrl, NULL,pk); print_key_info (ctrl, NULL, 0, pk, 0);
print_fingerprint (ctrl, NULL, pk, 2); print_fingerprint (ctrl, NULL, pk, 2);
tty_printf("\n"); tty_printf("\n");

View File

@ -305,11 +305,11 @@ gen_desig_revoke (ctrl_t ctrl, const char *uname, strlist_t locusr)
any = 1; any = 1;
print_pubkey_info (ctrl, NULL, pk); print_key_info (ctrl, NULL, 0, pk, 0);
tty_printf ("\n"); tty_printf ("\n");
tty_printf (_("To be revoked by:\n")); tty_printf (_("To be revoked by:\n"));
print_seckey_info (ctrl, pk2); print_key_info (ctrl, NULL, 0, pk2, 1);
if(pk->revkey[i].class&0x40) if(pk->revkey[i].class&0x40)
tty_printf(_("(This is a sensitive revocation key)\n")); tty_printf(_("(This is a sensitive revocation key)\n"));
@ -669,30 +669,26 @@ gen_revoke (ctrl_t ctrl, const char *uname)
rc = keydb_search (kdbhd, &desc, 1, NULL); rc = keydb_search (kdbhd, &desc, 1, NULL);
if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND) if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND)
/* Not ambiguous. */
{ {
/* Not ambiguous. */
} }
else if (rc == 0) else if (rc == 0)
/* Ambiguous. */
{ {
char *info; /* Ambiguous. */
/* TRANSLATORS: The %s prints a key specification which /* TRANSLATORS: The %s prints a key specification which
for example has been given at the command line. Several lines for example has been given at the command line. Several lines
lines with secret key infos are printed after this message. */ lines with secret key infos are printed after this message. */
log_error (_("'%s' matches multiple secret keys:\n"), uname); log_error (_("'%s' matches multiple secret keys:\n"), uname);
info = format_seckey_info (ctrl, keyblock->pkt->pkt.public_key); print_key_info_log (ctrl, GPGRT_LOGLVL_ERROR, 2,
log_error (" %s\n", info); keyblock->pkt->pkt.public_key, 1);
xfree (info);
release_kbnode (keyblock); release_kbnode (keyblock);
rc = keydb_get_keyblock (kdbhd, &keyblock); rc = keydb_get_keyblock (kdbhd, &keyblock);
while (! rc) while (! rc)
{ {
info = format_seckey_info (ctrl, keyblock->pkt->pkt.public_key); print_key_info_log (ctrl, GPGRT_LOGLVL_INFO, 2,
log_info (" %s\n", info); keyblock->pkt->pkt.public_key, 1);
xfree (info);
release_kbnode (keyblock); release_kbnode (keyblock);
keyblock = NULL; keyblock = NULL;
@ -726,7 +722,7 @@ gen_revoke (ctrl_t ctrl, const char *uname)
} }
keyid_from_pk (psk, keyid ); keyid_from_pk (psk, keyid );
print_seckey_info (ctrl, psk); print_key_info (ctrl, NULL, 0, psk, 1);
tty_printf("\n"); tty_printf("\n");
if (!cpr_get_answer_is_yes ("gen_revoke.okay", if (!cpr_get_answer_is_yes ("gen_revoke.okay",