Botan  2.7.0
Crypto and TLS for C++11
version.cpp
Go to the documentation of this file.
1 /*
2 * Version Information
3 * (C) 1999-2013,2015 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/version.h>
9 #include <sstream>
10 
11 namespace Botan {
12 
13 /*
14  These are intentionally compiled rather than inlined, so an
15  application running against a shared library can test the true
16  version they are running against.
17 */
18 
19 #define QUOTE(name) #name
20 #define STR(macro) QUOTE(macro)
21 
22 const char* short_version_cstr()
23  {
24  return STR(BOTAN_VERSION_MAJOR) "."
25  STR(BOTAN_VERSION_MINOR) "."
26  STR(BOTAN_VERSION_PATCH);
27  }
28 
29 const char* version_cstr()
30  {
31 
32  /*
33  It is intentional that this string is a compile-time constant;
34  it makes it much easier to find in binaries.
35  */
36 
37  return "Botan " STR(BOTAN_VERSION_MAJOR) "."
38  STR(BOTAN_VERSION_MINOR) "."
39  STR(BOTAN_VERSION_PATCH) " ("
40 #if defined(BOTAN_UNSAFE_FUZZER_MODE)
41  "UNSAFE FUZZER MODE BUILD "
42 #endif
43  BOTAN_VERSION_RELEASE_TYPE
44 #if (BOTAN_VERSION_DATESTAMP != 0)
45  ", dated " STR(BOTAN_VERSION_DATESTAMP)
46 #endif
47  ", revision " BOTAN_VERSION_VC_REVISION
48  ", distribution " BOTAN_DISTRIBUTION_INFO ")";
49  }
50 
51 #undef STR
52 #undef QUOTE
53 
54 /*
55 * Return the version as a string
56 */
57 std::string version_string()
58  {
59  return std::string(version_cstr());
60  }
61 
62 std::string short_version_string()
63  {
64  return std::string(short_version_cstr());
65  }
66 
67 uint32_t version_datestamp() { return BOTAN_VERSION_DATESTAMP; }
68 
69 /*
70 * Return parts of the version as integers
71 */
72 uint32_t version_major() { return BOTAN_VERSION_MAJOR; }
73 uint32_t version_minor() { return BOTAN_VERSION_MINOR; }
74 uint32_t version_patch() { return BOTAN_VERSION_PATCH; }
75 
76 std::string runtime_version_check(uint32_t major,
77  uint32_t minor,
78  uint32_t patch)
79  {
80  if(major != version_major() || minor != version_minor() || patch != version_patch())
81  {
82  std::ostringstream oss;
83  oss << "Warning: linked version (" << short_version_string() << ")"
84  << " does not match version built against "
85  << "(" << major << '.' << minor << '.' << patch << ")\n";
86  return oss.str();
87  }
88 
89  return "";
90  }
91 
92 }
#define STR(macro)
Definition: version.cpp:20
uint32_t version_major()
Definition: version.cpp:72
uint32_t version_patch()
Definition: version.cpp:74
const char * short_version_cstr()
Definition: version.cpp:22
Definition: alg_id.cpp:13
uint32_t version_minor()
Definition: version.cpp:73
std::string short_version_string()
Definition: version.cpp:62
uint32_t version_datestamp()
Definition: version.cpp:67
std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch)
Definition: version.cpp:76
std::string version_string()
Definition: version.cpp:57
const char * version_cstr()
Definition: version.cpp:29