Botan 2.19.5 Crypto and TLS for C&

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#if defined(BOTAN_VERSION_SUFFIX)
28 STR(BOTAN_VERSION_SUFFIX)
29#endif
30 ;
31 }
32
33 const char* version_cstr()
34 {
35
36 /*
37 It is intentional that this string is a compile-time constant;
38 it makes it much easier to find in binaries.
39 */
40
41 return "Botan " STR(BOTAN_VERSION_MAJOR) "."
42 STR(BOTAN_VERSION_MINOR) "."
43 STR(BOTAN_VERSION_PATCH)
44#if defined(BOTAN_VERSION_SUFFIX)
45 STR(BOTAN_VERSION_SUFFIX)
46#endif
47 " ("
48#if defined(BOTAN_UNSAFE_FUZZER_MODE)
49 "UNSAFE FUZZER MODE BUILD "
50#endif
51 BOTAN_VERSION_RELEASE_TYPE
52#if (BOTAN_VERSION_DATESTAMP != 0)
53 ", dated " STR(BOTAN_VERSION_DATESTAMP)
54#endif
55 ", revision " BOTAN_VERSION_VC_REVISION
56 ", distribution " BOTAN_DISTRIBUTION_INFO ")";
57 }
58
59#undef STR
60#undef QUOTE
61
62/*
63* Return the version as a string
64*/
65std::string version_string()
66 {
67 return std::string(version_cstr());
68 }
69
70std::string short_version_string()
71 {
72 return std::string(short_version_cstr());
73 }
74
75uint32_t version_datestamp() { return BOTAN_VERSION_DATESTAMP; }
76
77/*
78* Return parts of the version as integers
79*/
80uint32_t version_major() { return BOTAN_VERSION_MAJOR; }
81uint32_t version_minor() { return BOTAN_VERSION_MINOR; }
82uint32_t version_patch() { return BOTAN_VERSION_PATCH; }
83
84std::string runtime_version_check(uint32_t major,
85 uint32_t minor,
86 uint32_t patch)
87 {
88 if(major != version_major() || minor != version_minor() || patch != version_patch())
89 {
90 std::ostringstream oss;
91 oss << "Warning: linked version (" << short_version_string() << ")"
92 << " does not match version built against "
93 << "(" << major << '.' << minor << '.' << patch << ")\n";
94 return oss.str();
95 }
96
97 return "";
98 }
99
100}
Botan
Definition: alg_id.cpp:13
Botan::version_minor
uint32_t version_minor()
Definition: version.cpp:81
Botan::version_string
std::string version_string()
Definition: version.cpp:65
Botan::short_version_cstr
const char * short_version_cstr()
Definition: version.cpp:22
Botan::version_major
uint32_t version_major()
Definition: version.cpp:80
Botan::version_cstr
const char * version_cstr()
Definition: version.cpp:33
Botan::version_datestamp
uint32_t version_datestamp()
Definition: version.cpp:75
Botan::version_patch
uint32_t version_patch()
Definition: version.cpp:82
Botan::short_version_string
std::string short_version_string()
Definition: version.cpp:70
Botan::runtime_version_check
std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch)
Definition: version.cpp:84
STR
#define STR(macro)
Definition: version.cpp:20