/src/Botan-3.4.0/src/lib/utils/version.cpp
Line | Count | Source |
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 | | |
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 | | // NOLINTNEXTLINE(*-macro-usage) |
21 | 0 | #define QUOTE(name) #name |
22 | | // NOLINTNEXTLINE(*-macro-usage) |
23 | 0 | #define STR(macro) QUOTE(macro) |
24 | | |
25 | 0 | const char* short_version_cstr() { |
26 | 0 | return STR(BOTAN_VERSION_MAJOR) "." STR(BOTAN_VERSION_MINOR) "." STR(BOTAN_VERSION_PATCH) |
27 | | #if defined(BOTAN_VERSION_SUFFIX) |
28 | | STR(BOTAN_VERSION_SUFFIX) |
29 | | #endif |
30 | 0 | ; |
31 | 0 | } |
32 | | |
33 | 0 | const 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 | |
|
39 | 0 | return "Botan " STR(BOTAN_VERSION_MAJOR) "." STR(BOTAN_VERSION_MINOR) "." STR(BOTAN_VERSION_PATCH) |
40 | | #if defined(BOTAN_VERSION_SUFFIX) |
41 | | STR(BOTAN_VERSION_SUFFIX) |
42 | | #endif |
43 | 0 | " (" |
44 | 0 | #if defined(BOTAN_UNSAFE_FUZZER_MODE) || defined(BOTAN_TERMINATE_ON_ASSERTS) |
45 | 0 | "UNSAFE " |
46 | 0 | #if defined(BOTAN_UNSAFE_FUZZER_MODE) |
47 | 0 | "FUZZER MODE " |
48 | 0 | #endif |
49 | | #if defined(BOTAN_TERMINATE_ON_ASSERTS) |
50 | | "TERMINATE ON ASSERTS " |
51 | | #endif |
52 | 0 | "BUILD " |
53 | 0 | #endif |
54 | 0 | BOTAN_VERSION_RELEASE_TYPE |
55 | 0 | #if(BOTAN_VERSION_DATESTAMP != 0) |
56 | 0 | ", dated " STR(BOTAN_VERSION_DATESTAMP) |
57 | 0 | #endif |
58 | 0 | ", revision " BOTAN_VERSION_VC_REVISION ", distribution " BOTAN_DISTRIBUTION_INFO ")"; |
59 | 0 | } |
60 | | |
61 | | #undef STR |
62 | | #undef QUOTE |
63 | | |
64 | | /* |
65 | | * Return the version as a string |
66 | | */ |
67 | 0 | std::string version_string() { |
68 | 0 | return std::string(version_cstr()); |
69 | 0 | } |
70 | | |
71 | 0 | std::string short_version_string() { |
72 | 0 | return std::string(short_version_cstr()); |
73 | 0 | } |
74 | | |
75 | 0 | uint32_t version_datestamp() { |
76 | 0 | return BOTAN_VERSION_DATESTAMP; |
77 | 0 | } |
78 | | |
79 | | /* |
80 | | * Return parts of the version as integers |
81 | | */ |
82 | 0 | uint32_t version_major() { |
83 | 0 | return BOTAN_VERSION_MAJOR; |
84 | 0 | } |
85 | | |
86 | 0 | uint32_t version_minor() { |
87 | 0 | return BOTAN_VERSION_MINOR; |
88 | 0 | } |
89 | | |
90 | 0 | uint32_t version_patch() { |
91 | 0 | return BOTAN_VERSION_PATCH; |
92 | 0 | } |
93 | | |
94 | 0 | std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch) { |
95 | 0 | if(major != version_major() || minor != version_minor() || patch != version_patch()) { |
96 | 0 | return fmt("Warning: linked version ({}) does not match version built against ({}.{}.{})\n", |
97 | 0 | short_version_cstr(), |
98 | 0 | major, |
99 | 0 | minor, |
100 | 0 | patch); |
101 | 0 | } |
102 | | |
103 | 0 | return ""; |
104 | 0 | } |
105 | | |
106 | | } // namespace Botan |