From b48e6fb097c62bb246629ee7a182c57e497e4130 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 19 Dec 2015 15:36:40 -0500 Subject: CLI rewrite The command line tools' origin as a collection of examples and test programs glued together led to some unfortunate problems; lots of hardcoded values, missing parameters, and obsolete crypto. Adds a small library for writing command line programs of the sort needed here (cli.h), which cuts the length of many of the commands in half and makes commands more pleasant to write and extend. Generalizes a lot of the commands also, eg previously only signing/verification with DSA/SHA-1 was included! Removes the fuzzer entry point since that's fairly useless outside of an instrumented build. Removes the in-library API for benchmarking. --- src/lib/utils/stl_util.h | 15 +++++++++++++++ src/lib/utils/version.cpp | 24 +++++++++++++++++++++++- src/lib/utils/version.h | 13 ++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/stl_util.h b/src/lib/utils/stl_util.h index d74cbe713..12b749c3c 100644 --- a/src/lib/utils/stl_util.h +++ b/src/lib/utils/stl_util.h @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace Botan { @@ -26,6 +27,20 @@ inline std::string to_string(const secure_vector &bytes) return std::string(bytes.cbegin(), bytes.cend()); } +/** +* 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; + } + /* * Searching through a std::map * @param mapping the map to search diff --git a/src/lib/utils/version.cpp b/src/lib/utils/version.cpp index f3e01e290..8e14cc62f 100644 --- a/src/lib/utils/version.cpp +++ b/src/lib/utils/version.cpp @@ -1,12 +1,13 @@ /* * Version Information -* (C) 1999-2013 Jack Lloyd +* (C) 1999-2013,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include #include +#include namespace Botan { @@ -57,4 +58,25 @@ u32bit version_major() { return BOTAN_VERSION_MAJOR; } u32bit version_minor() { return BOTAN_VERSION_MINOR; } u32bit version_patch() { return BOTAN_VERSION_PATCH; } +std::string runtime_version_check(u32bit major, + u32bit minor, + u32bit patch) + { + std::ostringstream oss; + + if(major != version_major() || + minor != version_minor() || + patch != version_patch()) + { + oss << "Warning: linked version (" + << Botan::version_major() << '.' + << Botan::version_minor() << '.' + << Botan::version_patch() + << ") does not match version built against (" + << major << '.' << minor << '.' << patch << ")\n"; + } + + return oss.str(); + } + } diff --git a/src/lib/utils/version.h b/src/lib/utils/version.h index 3fc6f5fe7..406deae66 100644 --- a/src/lib/utils/version.h +++ b/src/lib/utils/version.h @@ -1,6 +1,6 @@ /* * Version Information -* (C) 1999-2011 Jack Lloyd +* (C) 1999-2011,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -54,6 +54,17 @@ BOTAN_DLL u32bit version_minor(); */ BOTAN_DLL u32bit version_patch(); +/** +* Usable for checking that the DLL version loaded at runtime exactly +* matches the compile-time version. Call using BOTAN_VERSION_* macro +* values. Returns the empty string if an exact match, otherwise an +* appropriate message. @added 1.11.26 +*/ +BOTAN_DLL std::string +runtime_version_check(u32bit major, + u32bit minor, + u32bit patch); + /* * Macros for compile-time version checks */ -- cgit v1.2.3