Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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