diff --git a/src/actions.cpp b/src/actions.cpp index 67add45..bff4558 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -139,9 +139,55 @@ int action_decrypt_verify (bool armor, keyring&KR, algorithm_suite&AS) * keyring stuff */ +static void output_key (bool fp, + const std::string& ident, const std::string&longid, + const std::string&alg, const std::string&keyid, + const std::string&name) +{ + + if (!fp) + out (ident << '\t' << alg << '\t' + << '@' << keyid.substr (0, 22) << "...\t" + << "\"" << name << "\""); + else { + out ( longid << " with algorithm " << alg + << ", name `" << name << "'"); + + std::cout << " fingerprint "; + for (size_t j = 0; j < keyid.length(); ++j) { + std::cout << keyid[j]; + if (! ( (j + 1) % 4) && + j < keyid.length() - 1) + std::cout << ':'; + } + std::cout << std::endl << std::endl; + } +} + int action_list (bool nice_fingerprint, const std::string&filter, keyring&KR) { + for (keyring::keypair_storage::iterator + i = KR.pairs.begin(), e = KR.pairs.end(); + i != e; ++i) { + + if (keyspec_matches (filter, i->second.pub.name, i->first) ) + + output_key (nice_fingerprint, + "pubkey", "public key in keypair", + i->second.pub.alg, i->first, + i->second.pub.name); + } + + for (keyring::pubkey_storage::iterator + i = KR.pubs.begin(), e = KR.pubs.end(); + i != e; ++i) { + if (keyspec_matches (filter, i->second.name, i->first) ) + output_key (nice_fingerprint, + "pubkey", "public key", + i->second.alg, i->first, + i->second.name); + } return 0; } @@ -184,27 +230,11 @@ int action_list_sec (bool nice_fingerprint, const std::string&filter, i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (!keyspec_matches (filter, i->second.pub.name, i->first) ) - continue; - - if (!nice_fingerprint) - out ("keypair\t" - << i->second.pub.alg << '\t' - << '@' << i->first.substr (0, 22) << "...\t" - << "\"" << i->second.pub.name << "\""); - else { - out ("key pair with algorithm " << i->second.pub.alg - << ", name `" << i->second.pub.name << "'"); - - std::cout << " fingerprint "; - for (size_t j = 0; j < i->first.length(); ++j) { - std::cout << i->first[j]; - if (! ( (j + 1) % 4) && - j < i->first.length() - 1) - std::cout << ':'; - } - std::cout << std::endl << std::endl; - } + if (keyspec_matches (filter, i->second.pub.name, i->first) ) + output_key (nice_fingerprint, + "keypair", "key pair", + i->second.pub.alg, i->first, + i->second.pub.name); } return 0; }