Botan 3.0.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#include <botan/internal/fmt.h>
10
11namespace 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// NOLINTNEXTLINE(*-macro-usage)
20#define QUOTE(name) #name
21// NOLINTNEXTLINE(*-macro-usage)
22#define STR(macro) QUOTE(macro)
23
24const char* short_version_cstr()
25 {
26 return STR(BOTAN_VERSION_MAJOR) "."
29#if defined(BOTAN_VERSION_SUFFIX)
30 STR(BOTAN_VERSION_SUFFIX)
31#endif
32 ;
33 }
34
35const char* version_cstr()
36 {
37
38 /*
39 It is intentional that this string is a compile-time constant;
40 it makes it much easier to find in binaries.
41 */
42
43 return "Botan " STR(BOTAN_VERSION_MAJOR) "."
46#if defined(BOTAN_VERSION_SUFFIX)
47 STR(BOTAN_VERSION_SUFFIX)
48#endif
49 " ("
50#if defined(BOTAN_UNSAFE_FUZZER_MODE)
51 "UNSAFE FUZZER MODE BUILD "
52#endif
54#if (BOTAN_VERSION_DATESTAMP != 0)
56#endif
57 ", revision " BOTAN_VERSION_VC_REVISION
58 ", 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 {
69 return std::string(version_cstr());
70 }
71
73 {
74 return std::string(short_version_cstr());
75 }
76
78
79/*
80* Return parts of the version as integers
81*/
82uint32_t version_major() { return BOTAN_VERSION_MAJOR; }
83uint32_t version_minor() { return BOTAN_VERSION_MINOR; }
84uint32_t version_patch() { return BOTAN_VERSION_PATCH; }
85
86std::string runtime_version_check(uint32_t major,
87 uint32_t minor,
88 uint32_t patch)
89 {
90 if(major != version_major() || minor != version_minor() || patch != version_patch())
91 {
92 return fmt("Warning: linked version ({}) does not match version built against ({}.{}.{})\n",
93 short_version_cstr(), major, minor, patch);
94 }
95
96 return "";
97 }
98
99}
#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
Definition: alg_id.cpp:12
uint32_t version_minor()
Definition: version.cpp:83
std::string version_string()
Definition: version.cpp:67
std::string fmt(std::string_view format, const T &... args)
Definition: fmt.h:60
const char * short_version_cstr()
Definition: version.cpp:24
uint32_t version_major()
Definition: version.cpp:82
const char * version_cstr()
Definition: version.cpp:35
uint32_t version_datestamp()
Definition: version.cpp:77
uint32_t version_patch()
Definition: version.cpp:84
std::string short_version_string()
Definition: version.cpp:72
std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch)
Definition: version.cpp:86
#define STR(macro)
Definition: version.cpp:22