diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index 2761b0dd065..6fa42fd6fb6 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -66,12 +66,19 @@ class Print_Help final : public Command { oss << "Available commands:\n\n"; for(const auto& commands : grouped_commands) { - std::string desc = commands.first; - if(desc.empty()) { + const std::string group = commands.first; + if(group.empty()) { + // ??? continue; } - oss << Botan::search_map(groups_description, desc, desc) << ":\n"; + auto descr = groups_description.find(group); + if(descr != groups_description.end()) { + oss << descr->second; + } else { + oss << group; + } + oss << ":\n"; for(const auto& cmd : commands.second) { oss << " " << std::setw(16) << std::left << cmd->cmd_name() << " " << cmd->description() << "\n"; } diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp index 4c2dd35bdbf..c88c3894ff4 100644 --- a/src/lib/utils/http_util/http_util.cpp +++ b/src/lib/utils/http_util/http_util.cpp @@ -214,9 +214,9 @@ Response http_sync(const http_exch_fn& http_transact, resp_body.insert(resp_body.end(), buf.data(), &buf[got]); } - const std::string header_size = search_map(headers, std::string("Content-Length")); - - if(!header_size.empty()) { + auto cl_hdr = headers.find("Content-Length"); + if(cl_hdr != headers.end()) { + const std::string header_size = cl_hdr->second; if(resp_body.size() != to_u32bit(header_size)) { throw HTTP_Error(fmt("Content-Length disagreement, header says {} got {}", header_size, resp_body.size())); } diff --git a/src/lib/utils/stl_util.h b/src/lib/utils/stl_util.h index 26f624370d3..2629350f21e 100644 --- a/src/lib/utils/stl_util.h +++ b/src/lib/utils/stl_util.h @@ -11,9 +11,7 @@ #include #include -#include #include -#include #include #include #include @@ -54,63 +52,6 @@ RetT reduce(const std::vector& keys, RetT acc, ReducerT reducer) return acc; } -/** -* Return the keys of a map as a std::set -*/ -template -std::set map_keys_as_set(const std::map& kv) { - std::set s; - for(auto&& i : kv) { - s.insert(i.first); - } - return s; -} - -/** -* Return the keys of a multimap as a std::set -*/ -template -std::set map_keys_as_set(const std::multimap& kv) { - std::set s; - for(auto&& i : kv) { - s.insert(i.first); - } - return s; -} - -/* -* Searching through a std::map -* @param mapping the map to search -* @param key is what to look for -* @param null_result is the value to return if key is not in mapping -* @return mapping[key] or null_result -*/ -template -inline V search_map(const std::map& mapping, const K& key, const V& null_result = V()) { - auto i = mapping.find(key); - if(i == mapping.end()) { - return null_result; - } - return i->second; -} - -template -inline R search_map(const std::map& mapping, const K& key, const R& null_result, const R& found_result) { - auto i = mapping.find(key); - if(i == mapping.end()) { - return null_result; - } - return found_result; -} - -/* -* Insert a key/value pair into a multimap -*/ -template -void multimap_insert(std::multimap& multimap, const K& key, const V& value) { - multimap.insert(std::make_pair(key, value)); -} - /** * Existence check for values */ diff --git a/src/lib/x509/asn1_alt_name.cpp b/src/lib/x509/asn1_alt_name.cpp index 08bace9e3af..8fff9145c21 100644 --- a/src/lib/x509/asn1_alt_name.cpp +++ b/src/lib/x509/asn1_alt_name.cpp @@ -56,7 +56,7 @@ void AlternativeName::add_othername(const OID& oid, std::string_view value, ASN1 if(value.empty()) { return; } - multimap_insert(m_othernames, oid, ASN1_String(value, type)); + m_othernames.emplace(oid, ASN1_String{value, type}); } /* @@ -70,7 +70,7 @@ std::multimap AlternativeName::contents() const { } for(const auto& othername : m_othernames) { - multimap_insert(names, othername.first.to_formatted_string(), othername.second.value()); + names.emplace(othername.first.to_formatted_string(), othername.second.value()); } return names; diff --git a/src/lib/x509/x509_dn.cpp b/src/lib/x509/x509_dn.cpp index bf2a5357829..1f7a9e21c47 100644 --- a/src/lib/x509/x509_dn.cpp +++ b/src/lib/x509/x509_dn.cpp @@ -113,7 +113,7 @@ std::multimap X509_DN::get_attributes() const { std::multimap retval; for(auto& i : m_rdn) { - multimap_insert(retval, i.first, i.second.value()); + retval.emplace(i.first, i.second.value()); } return retval; } @@ -125,7 +125,7 @@ std::multimap X509_DN::contents() const { std::multimap retval; for(auto& i : m_rdn) { - multimap_insert(retval, i.first.to_formatted_string(), i.second.value()); + retval.emplace(i.first.to_formatted_string(), i.second.value()); } return retval; } diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index c6ce80b7884..683fb2c235c 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -519,9 +519,21 @@ class Test_Registry { return nullptr; } - std::set registered_tests() const { return Botan::map_keys_as_set(m_tests); } + std::set registered_tests() const { + std::set s; + for(auto&& i : m_tests) { + s.insert(i.first); + } + return s; + } - std::set registered_test_categories() const { return Botan::map_keys_as_set(m_categories); } + std::set registered_test_categories() const { + std::set s; + for(auto&& i : m_categories) { + s.insert(i.first); + } + return s; + } std::vector filter_registered_tests(const std::vector& requested, const std::set& to_be_skipped) {