Botan 3.4.0
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
10#include <botan/internal/fmt.h>
11
12namespace 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// NOLINTNEXTLINE(*-macro-usage)
21#define QUOTE(name) #name
22// NOLINTNEXTLINE(*-macro-usage)
23#define STR(macro) QUOTE(macro)
24
25const char* short_version_cstr() {
27#if defined(BOTAN_VERSION_SUFFIX)
28 STR(BOTAN_VERSION_SUFFIX)
29#endif
30 ;
31}
32
33const char* version_cstr() {
34 /*
35 It is intentional that this string is a compile-time constant;
36 it makes it much easier to find in binaries.
37 */
38
40#if defined(BOTAN_VERSION_SUFFIX)
41 STR(BOTAN_VERSION_SUFFIX)
42#endif
43 " ("
44#if defined(BOTAN_UNSAFE_FUZZER_MODE) || defined(BOTAN_TERMINATE_ON_ASSERTS)
45 "UNSAFE "
46 #if defined(BOTAN_UNSAFE_FUZZER_MODE)
47 "FUZZER MODE "
48 #endif
49 #if defined(BOTAN_TERMINATE_ON_ASSERTS)
50 "TERMINATE ON ASSERTS "
51 #endif
52 "BUILD "
53#endif
55#if(BOTAN_VERSION_DATESTAMP != 0)
57#endif
58 ", revision " BOTAN_VERSION_VC_REVISION ", distribution " BOTAN_DISTRIBUTION_INFO ")";
59}
60
61#undef STR
62#undef QUOTE
63
64/*
65* Return the version as a string
66*/
67std::string version_string() {
68 return std::string(version_cstr());
69}
70
71std::string short_version_string() {
72 return std::string(short_version_cstr());
73}
74
77}
78
79/*
80* Return parts of the version as integers
81*/
82uint32_t version_major() {
84}
85
86uint32_t version_minor() {
88}
89
90uint32_t version_patch() {
92}
93
94std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch) {
95 if(major != version_major() || minor != version_minor() || patch != version_patch()) {
96 return fmt("Warning: linked version ({}) does not match version built against ({}.{}.{})\n",
98 major,
99 minor,
100 patch);
101 }
102
103 return "";
104}
105
106} // namespace Botan
#define BOTAN_DISTRIBUTION_INFO
Definition build.h:37
#define BOTAN_VERSION_PATCH
Definition build.h:29
#define BOTAN_VERSION_VC_REVISION
Definition build.h:35
#define BOTAN_VERSION_DATESTAMP
Definition build.h:30
#define BOTAN_VERSION_RELEASE_TYPE
Definition build.h:33
#define BOTAN_VERSION_MINOR
Definition build.h:28
#define BOTAN_VERSION_MAJOR
Definition build.h:27
uint32_t version_minor()
Definition version.cpp:86
std::string version_string()
Definition version.cpp:67
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
const char * short_version_cstr()
Definition version.cpp:25
uint32_t version_major()
Definition version.cpp:82
const char * version_cstr()
Definition version.cpp:33
uint32_t version_datestamp()
Definition version.cpp:75
uint32_t version_patch()
Definition version.cpp:90
std::string short_version_string()
Definition version.cpp:71
std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch)
Definition version.cpp:94
#define STR(macro)
Definition version.cpp:23