Botan 3.8.1
Crypto and TLS for C&
version.h
Go to the documentation of this file.
1/*
2* Version Information
3* (C) 1999-2011,2015 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_VERSION_H_
9#define BOTAN_VERSION_H_
10
11#include <botan/types.h>
12#include <optional>
13#include <string>
14
15namespace Botan {
16
17/*
18* Get information describing the version
19*/
20
21/**
22* Get a human-readable single-line string identifying the version of Botan.
23* No particular format should be assumed.
24* @return version string
25*/
26BOTAN_PUBLIC_API(2, 0) std::string version_string();
27
28/**
29* Same as version_string() except returning a pointer to a statically
30* allocated string.
31* @return version string
32*/
33BOTAN_PUBLIC_API(2, 0) const char* version_cstr();
34
35/**
36* Return a version string of the form "MAJOR.MINOR.PATCH" where
37* each of the values is an integer.
38*/
39BOTAN_PUBLIC_API(2, 4) std::string short_version_string();
40
41/**
42* Same as version_short_string except returning a pointer to the string.
43*/
44BOTAN_PUBLIC_API(2, 4) const char* short_version_cstr();
45
46/**
47* Return the date this version of botan was released, in an integer of
48* the form YYYYMMDD. For instance a version released on May 21, 2013
49* would return the integer 20130521. If the currently running version
50* is not an official release, this function will return 0 instead.
51*
52* @return release date, or zero if unreleased
53*/
54BOTAN_PUBLIC_API(2, 0) uint32_t version_datestamp();
55
56/**
57* Get the major version number.
58* @return major version number
59*/
60BOTAN_PUBLIC_API(2, 0) uint32_t version_major();
61
62/**
63* Get the minor version number.
64* @return minor version number
65*/
66BOTAN_PUBLIC_API(2, 0) uint32_t version_minor();
67
68/**
69* Get the patch number.
70* @return patch number
71*/
72BOTAN_PUBLIC_API(2, 0) uint32_t version_patch();
73
74/**
75* Returns a string that is set to a revision identifier corresponding to the
76* source, or `nullopt` if this could not be determined. It is set for all
77* official releases, and for builds that originated from within a git checkout.
78*
79* @return VC revision
80*/
81BOTAN_PUBLIC_API(3, 8) std::optional<std::string> version_vc_revision();
82
83/**
84* Return any string that is set at build time using the `--distribution-info`
85* option. It allows a packager of the library to specify any distribution-specific
86* patches. If no value is given at build time, returns `nullopt`.
87*
88* @return distribution info
89*/
90BOTAN_PUBLIC_API(3, 8) std::optional<std::string> version_distribution_info();
91
92/**
93* Usable for checking that the DLL version loaded at runtime exactly matches the
94* compile-time version. Call using BOTAN_VERSION_* macro values, like so:
95*
96* ```
97* Botan::runtime_version_check(BOTAN_VERSION_MAJOR, BOTAN_VERSION_MINOR, BOTAN_VERSION_PATCH);
98* ```
99*
100* It will return an empty string if the versions match, or otherwise an error
101* message indicating the discrepancy. This only is useful in dynamic libraries,
102* where it is possible to compile and run against different versions.
103*/
104BOTAN_PUBLIC_API(2, 0) std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch);
105
106/**
107* Certain build-time options, used for testing, result in a binary which is not
108* safe for use in a production system. This function can be used to test for such
109* a configuration at runtime.
110*
111* Currently these unsafe conditions include:
112*
113* - Unsafe fuzzer mode (--unsafe-fuzzer-mode) which intentionally disables various
114* checks in order to improve the effectiveness of fuzzing.
115* - Terminate on asserts (--unsafe-terminate-on-asserts) which intentionally aborts
116* if any internal assertion failure occurs, rather than throwing an exception.
117*/
119
120/*
121* Macros for compile-time version checks
122*
123* Return a value that can be used to compare versions. The current
124* (compile-time) version is available as the macro BOTAN_VERSION_CODE. For
125* instance, to choose one code path for version 3.1.0 and later, and another
126* code path for older releases:
127*
128* ```
129* #if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(3,1,0)
130* // 3.1+ code path
131* #else
132* // code path for older versions
133* #endif
134* ```
135*/
136#define BOTAN_VERSION_CODE_FOR(a, b, c) ((a << 16) | (b << 8) | (c))
137
138/**
139* Compare using BOTAN_VERSION_CODE_FOR, as in
140* # if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,8,0)
141* # error "Botan version too old"
142* # endif
143*/
144#define BOTAN_VERSION_CODE BOTAN_VERSION_CODE_FOR(BOTAN_VERSION_MAJOR, BOTAN_VERSION_MINOR, BOTAN_VERSION_PATCH)
145
146} // namespace Botan
147
148#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
uint32_t version_minor()
Definition version.cpp:59
std::string version_string()
Definition version.cpp:24
const char * short_version_cstr()
Definition version.cpp:16
uint32_t version_major()
Definition version.cpp:55
const char * version_cstr()
Definition version.cpp:20
uint32_t version_datestamp()
Definition version.cpp:32
std::optional< std::string > version_distribution_info()
Definition version.cpp:44
uint32_t version_patch()
Definition version.cpp:63
std::string short_version_string()
Definition version.cpp:28
std::optional< std::string > version_vc_revision()
Definition version.cpp:36
std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch)
Definition version.cpp:75
bool unsafe_for_production_build()
Definition version.cpp:67