diff --git a/doc/gpg.texi b/doc/gpg.texi index f19058146..f092b270d 100644 --- a/doc/gpg.texi +++ b/doc/gpg.texi @@ -342,7 +342,8 @@ fingerprints. This is the same output as @option{--list-keys} but with the additional output of a line with the fingerprint. May also be combined with @option{--list-sigs} or @option{--check-sigs}. If this command is given twice, the fingerprints of all secondary keys are -listed too. +listed too. This command also forces pretty printing of fingerprints +if the keyid format has been set to "none". @item --list-packets @opindex list-packets @@ -2276,6 +2277,14 @@ allow to convey suitable information for elliptic curves. Same as the command @option{--fingerprint} but changes only the format of the output and may be used together with another command. +@item --with-subkey-fingerprint +@opindex with-subkey-fingerprint +If a fingerprint is printed for the primary key, this option forces +printing of the fingerprint for all subkeys. This could also be +achieved by using the @option{--with-fingerprint} twice but by using +this option along with keyid-format "none" a compact fingerprint is +printed. + @item --with-icao-spelling @opindex with-icao-spelling Print the ICAO spelling of the fingerprint in addition to the hex digits. diff --git a/g10/gpg.c b/g10/gpg.c index d0be4ba3f..5b4fba611 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -182,6 +182,7 @@ enum cmd_and_opt_values oNoAskCertLevel, oFingerprint, oWithFingerprint, + oWithSubkeyFingerprint, oWithICAOSpelling, oWithKeygrip, oWithSecret, @@ -720,6 +721,8 @@ static ARGPARSE_OPTS opts[] = { ARGPARSE_s_n (oUtf8Strings, "utf8-strings", "@"), ARGPARSE_s_n (oNoUtf8Strings, "no-utf8-strings", "@"), ARGPARSE_s_n (oWithFingerprint, "with-fingerprint", "@"), + ARGPARSE_s_n (oWithSubkeyFingerprint, "with-subkey-fingerprint", "@"), + ARGPARSE_s_n (oWithSubkeyFingerprint, "with-subkey-fingerprints", "@"), ARGPARSE_s_n (oWithICAOSpelling, "with-icao-spelling", "@"), ARGPARSE_s_n (oWithKeygrip, "with-keygrip", "@"), ARGPARSE_s_n (oWithSecret, "with-secret", "@"), @@ -2566,6 +2569,9 @@ main (int argc, char **argv) opt.with_fingerprint = 1; opt.fingerprint++; break; + case oWithSubkeyFingerprint: + opt.with_subkey_fingerprint = 1; + break; case oWithICAOSpelling: opt.with_icao_spelling = 1; break; diff --git a/g10/keyid.c b/g10/keyid.c index 20efa01b7..4cdc41d2a 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -384,6 +384,9 @@ keystrlen(void) switch(format) { + case KF_NONE: + return 0; + case KF_SHORT: return 8; diff --git a/g10/keylist.c b/g10/keylist.c index abd5ffa3e..231f3c00e 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -1168,7 +1168,7 @@ list_keyblock_print (ctrl_t ctrl, kbnode_t keyblock, int secret, int fpr, /* Print the "sub" line. */ print_key_line (es_stdout, pk2, secret); - if (fpr > 1) + if (fpr > 1 || opt.with_subkey_fingerprint) { print_fingerprint (NULL, pk2, 0); if (serialno) @@ -1821,6 +1821,10 @@ print_fingerprint (estream_t override_fp, PKT_public_key *pk, int mode) compact = 1; } + if (!opt.fingerprint && !opt.with_fingerprint + && opt.with_subkey_fingerprint && opt.keyid_format == KF_NONE) + compact = 1; + if (pk->main_keyid[0] == pk->keyid[0] && pk->main_keyid[1] == pk->keyid[1]) primary = 1; @@ -1873,7 +1877,13 @@ print_fingerprint (estream_t override_fp, PKT_public_key *pk, int mode) else { fp = override_fp? override_fp : es_stdout; - text = _(" Key fingerprint ="); + if (opt.keyid_format == KF_NONE) + { + text = " "; /* To indent ICAO spelling. */ + compact = 1; + } + else + text = _(" Key fingerprint ="); } hexfingerprint (pk, hexfpr, sizeof hexfpr); @@ -1881,7 +1891,7 @@ print_fingerprint (estream_t override_fp, PKT_public_key *pk, int mode) { es_fprintf (fp, "fpr:::::::::%s:", hexfpr); } - else if (compact) + else if (compact && !opt.fingerprint && !opt.with_fingerprint) { tty_fprintf (fp, "%*s%s", 6, "", hexfpr); } @@ -1889,7 +1899,10 @@ print_fingerprint (estream_t override_fp, PKT_public_key *pk, int mode) { char fmtfpr[MAX_FORMATTED_FINGERPRINT_LEN + 1]; format_hexfingerprint (hexfpr, fmtfpr, sizeof fmtfpr); - tty_fprintf (fp, "%s %s", text, fmtfpr); + if (compact) + tty_fprintf (fp, "%*s%s", 6, "", fmtfpr); + else + tty_fprintf (fp, "%s %s", text, fmtfpr); } tty_fprintf (fp, "\n"); if (!with_colons && with_icao) diff --git a/g10/options.h b/g10/options.h index 55f974a8f..2ae1724c3 100644 --- a/g10/options.h +++ b/g10/options.h @@ -71,6 +71,7 @@ struct int with_key_data; int with_icao_spelling; /* Print ICAO spelling with fingerprints. */ int with_fingerprint; /* Option --with-fingerprint active. */ + int with_subkey_fingerprint; /* Option --with-subkey-fingerprint active. */ int with_keygrip; /* Option --with-keygrip active. */ int with_secret; /* Option --with-secret active. */ int with_wkd_hash; /* Option --with-wkd-hash. */