diff options
Diffstat (limited to 'src/lib/utils')
-rw-r--r-- | src/lib/utils/stl_util.h | 15 | ||||
-rw-r--r-- | src/lib/utils/version.cpp | 24 | ||||
-rw-r--r-- | src/lib/utils/version.h | 13 |
3 files changed, 50 insertions, 2 deletions
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 <vector> #include <string> #include <map> +#include <set> #include <botan/secmem.h> namespace Botan { @@ -26,6 +27,20 @@ inline std::string to_string(const secure_vector<byte> &bytes) return std::string(bytes.cbegin(), bytes.cend()); } +/** +* Return the keys of a map as a std::set +*/ +template<typename K, typename V> +std::set<K> map_keys_as_set(const std::map<K, V>& kv) + { + std::set<K> 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 <botan/version.h> #include <botan/parsing.h> +#include <sstream> 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 */ |