/src/botan/build/include/public/botan/assert.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Runtime assertion checking |
3 | | * (C) 2010,2018 Jack Lloyd |
4 | | * 2017 Simon Warta (Kullo GmbH) |
5 | | * |
6 | | * Botan is released under the Simplified BSD License (see license.txt) |
7 | | */ |
8 | | |
9 | | #ifndef BOTAN_ASSERTION_CHECKING_H_ |
10 | | #define BOTAN_ASSERTION_CHECKING_H_ |
11 | | |
12 | | #include <botan/compiler.h> |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | | /** |
17 | | * Called when an assertion fails |
18 | | * Throws an Exception object |
19 | | */ |
20 | | [[noreturn]] void BOTAN_PUBLIC_API(2, 0) |
21 | | assertion_failure(const char* expr_str, const char* assertion_made, const char* func, const char* file, int line); |
22 | | |
23 | | /** |
24 | | * Called when an invalid argument is used |
25 | | * Throws Invalid_Argument |
26 | | */ |
27 | | [[noreturn]] void BOTAN_UNSTABLE_API throw_invalid_argument(const char* message, const char* func, const char* file); |
28 | | |
29 | | #define BOTAN_ARG_CHECK(expr, msg) \ |
30 | 58.6M | do { \ |
31 | 58.6M | if(!(expr)) \ Unexecuted instantiation: hybrid_public_key.cpp:auto Botan::TLS::Hybrid_KEM_PublicKey::Hybrid_KEM_PublicKey(std::__1::vector<std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> >, std::__1::allocator<std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> > > >)::$_0::operator()<std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> > >(std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> > const&) const Unexecuted instantiation: hybrid_public_key.cpp:auto Botan::TLS::Hybrid_KEM_PublicKey::Hybrid_KEM_PublicKey(std::__1::vector<std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> >, std::__1::allocator<std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> > > >)::$_1::operator()<std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> > >(std::__1::unique_ptr<Botan::Public_Key, std::__1::default_delete<Botan::Public_Key> > const&) const Unexecuted instantiation: hybrid_public_key.cpp:auto Botan::TLS::Hybrid_KEM_PrivateKey::Hybrid_KEM_PrivateKey(std::__1::vector<std::__1::unique_ptr<Botan::Private_Key, std::__1::default_delete<Botan::Private_Key> >, std::__1::allocator<std::__1::unique_ptr<Botan::Private_Key, std::__1::default_delete<Botan::Private_Key> > > >)::$_0::operator()<std::__1::unique_ptr<Botan::Private_Key, std::__1::default_delete<Botan::Private_Key> > >(std::__1::unique_ptr<Botan::Private_Key, std::__1::default_delete<Botan::Private_Key> > const&) const |
32 | 58.6M | Botan::throw_invalid_argument(msg, __func__, __FILE__); \ |
33 | 58.6M | } while(0) |
34 | | |
35 | | /** |
36 | | * Called when an invalid state is encountered |
37 | | * Throws Invalid_State |
38 | | */ |
39 | | [[noreturn]] void BOTAN_UNSTABLE_API throw_invalid_state(const char* message, const char* func, const char* file); |
40 | | |
41 | | #define BOTAN_STATE_CHECK(expr) \ |
42 | 3.68M | do { \ |
43 | 3.68M | if(!(expr)) \ |
44 | 3.68M | Botan::throw_invalid_state(#expr, __func__, __FILE__); \ |
45 | 3.68M | } while(0) |
46 | | |
47 | | /** |
48 | | * Make an assertion |
49 | | */ |
50 | | #define BOTAN_ASSERT(expr, assertion_made) \ |
51 | 589M | do { \ |
52 | 589M | if(!(expr)) \ |
53 | 589M | Botan::assertion_failure(#expr, assertion_made, __func__, __FILE__, __LINE__); \ |
54 | 589M | } while(0) |
55 | | |
56 | | /** |
57 | | * Make an assertion |
58 | | */ |
59 | | #define BOTAN_ASSERT_NOMSG(expr) \ |
60 | 33.2M | do { \ |
61 | 33.2M | if(!(expr)) \ |
62 | 33.2M | Botan::assertion_failure(#expr, "", __func__, __FILE__, __LINE__); \ |
63 | 33.2M | } while(0) |
64 | | |
65 | | /** |
66 | | * Assert that value1 == value2 |
67 | | */ |
68 | | #define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made) \ |
69 | 197k | do { \ |
70 | 197k | if((expr1) != (expr2)) \ |
71 | 197k | Botan::assertion_failure(#expr1 " == " #expr2, assertion_made, __func__, __FILE__, __LINE__); \ |
72 | 197k | } while(0) |
73 | | |
74 | | /** |
75 | | * Assert that expr1 (if true) implies expr2 is also true |
76 | | */ |
77 | | #define BOTAN_ASSERT_IMPLICATION(expr1, expr2, msg) \ |
78 | 192M | do { \ |
79 | 382M | if((expr1) && !(expr2)) \ |
80 | 192M | Botan::assertion_failure(#expr1 " implies " #expr2, msg, __func__, __FILE__, __LINE__); \ |
81 | 192M | } while(0) |
82 | | |
83 | | /** |
84 | | * Assert that a pointer is not null |
85 | | */ |
86 | | #define BOTAN_ASSERT_NONNULL(ptr) \ |
87 | 3.77M | do { \ |
88 | 3.77M | if((ptr) == nullptr) \ |
89 | 3.77M | Botan::assertion_failure(#ptr " is not null", "", __func__, __FILE__, __LINE__); \ |
90 | 3.77M | } while(0) |
91 | | |
92 | | #if defined(BOTAN_ENABLE_DEBUG_ASSERTS) |
93 | | |
94 | | #define BOTAN_DEBUG_ASSERT(expr) BOTAN_ASSERT_NOMSG(expr) |
95 | | |
96 | | #else |
97 | | |
98 | | #define BOTAN_DEBUG_ASSERT(expr) \ |
99 | 706M | do { \ |
100 | 706M | } while(0) |
101 | | |
102 | | #endif |
103 | | |
104 | | /** |
105 | | * Mark variable as unused. |
106 | | * |
107 | | * Takes any number of arguments and marks all as unused, for instance |
108 | | * BOTAN_UNUSED(a); or BOTAN_UNUSED(x, y, z); |
109 | | */ |
110 | | template <typename T> |
111 | 546M | constexpr void ignore_param(T&&) {} void Botan::ignore_param<unsigned long const*&>(unsigned long const*&) Line | Count | Source | 111 | 260M | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<unsigned long&>(unsigned long&) Line | Count | Source | 111 | 261M | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<unsigned long const&>(unsigned long const&) Line | Count | Source | 111 | 23.9M | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<std::__1::vector<Botan::BigInt, std::__1::allocator<Botan::BigInt> >&>(std::__1::vector<Botan::BigInt, std::__1::allocator<Botan::BigInt> >&) Line | Count | Source | 111 | 11.7k | constexpr void ignore_param(T&&) {} |
Unexecuted instantiation: void Botan::ignore_param<Botan::SCAN_Name const&>(Botan::SCAN_Name const&) void Botan::ignore_param<std::__1::basic_string_view<char, std::__1::char_traits<char> >&>(std::__1::basic_string_view<char, std::__1::char_traits<char> >&) Line | Count | Source | 111 | 600 | constexpr void ignore_param(T&&) {} |
Unexecuted instantiation: void Botan::ignore_param<void*&>(void*&) void Botan::ignore_param<unsigned char const*&>(unsigned char const*&) Line | Count | Source | 111 | 234k | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<unsigned short const*&>(unsigned short const*&) Line | Count | Source | 111 | 141 | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<std::__1::span<unsigned char const, 18446744073709551615ul>&>(std::__1::span<unsigned char const, 18446744073709551615ul>&) Line | Count | Source | 111 | 328 | constexpr void ignore_param(T&&) {} |
Unexecuted instantiation: void Botan::ignore_param<unsigned int const*&>(unsigned int const*&) void Botan::ignore_param<Botan::TLS::Session_Summary const&>(Botan::TLS::Session_Summary const&) Line | Count | Source | 111 | 82 | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<std::__1::vector<Botan::X509_Certificate, std::__1::allocator<Botan::X509_Certificate> > const&>(std::__1::vector<Botan::X509_Certificate, std::__1::allocator<Botan::X509_Certificate> > const&) Line | Count | Source | 111 | 32 | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<Botan::TLS::Certificate_Status_Request const&>(Botan::TLS::Certificate_Status_Request const&) Line | Count | Source | 111 | 32 | constexpr void ignore_param(T&&) {} |
Unexecuted instantiation: void Botan::ignore_param<char const*&>(char const*&) Unexecuted instantiation: void Botan::ignore_param<Botan::RandomNumberGenerator&>(Botan::RandomNumberGenerator&) Unexecuted instantiation: void Botan::ignore_param<Botan::Public_Key const&>(Botan::Public_Key const&) Unexecuted instantiation: void Botan::ignore_param<Botan::Usage_Type&>(Botan::Usage_Type&) Unexecuted instantiation: void Botan::ignore_param<Botan::TLS::Policy const&>(Botan::TLS::Policy const&) Unexecuted instantiation: void Botan::ignore_param<bool&>(bool&) Unexecuted instantiation: void Botan::ignore_param<short const*&>(short const*&) Unexecuted instantiation: void Botan::ignore_param<Botan::EC_Group const&>(Botan::EC_Group const&) Unexecuted instantiation: void Botan::ignore_param<Botan::TLS::Client_Hello_12 const&>(Botan::TLS::Client_Hello_12 const&) Unexecuted instantiation: void Botan::ignore_param<Botan::X25519_PublicKey const*&>(Botan::X25519_PublicKey const*&) Unexecuted instantiation: void Botan::ignore_param<Botan::X448_PublicKey const*&>(Botan::X448_PublicKey const*&) void Botan::ignore_param<Botan::TLS::Protocol_Version&>(Botan::TLS::Protocol_Version&) Line | Count | Source | 111 | 18.0k | constexpr void ignore_param(T&&) {} |
void Botan::ignore_param<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 111 | 116 | constexpr void ignore_param(T&&) {} |
Unexecuted instantiation: void Botan::ignore_param<Botan::Classic_McEliece_GF const*&>(Botan::Classic_McEliece_GF const*&) Unexecuted instantiation: void Botan::ignore_param<bool const*&>(bool const*&) Unexecuted instantiation: void Botan::ignore_param<int const*&>(int const*&) Unexecuted instantiation: void Botan::ignore_param<bool const&>(bool const&) Unexecuted instantiation: void Botan::ignore_param<Botan::TLS::Connection_Side const&>(Botan::TLS::Connection_Side const&) |
112 | | |
113 | | template <typename... T> |
114 | 273M | constexpr void ignore_params(T&&... args) { |
115 | 273M | (ignore_param(args), ...); |
116 | 273M | } void Botan::ignore_params<unsigned long const*&, unsigned long&>(unsigned long const*&, unsigned long&) Line | Count | Source | 114 | 260M | constexpr void ignore_params(T&&... args) { | 115 | 260M | (ignore_param(args), ...); | 116 | 260M | } |
void Botan::ignore_params<unsigned long&>(unsigned long&) Line | Count | Source | 114 | 927k | constexpr void ignore_params(T&&... args) { | 115 | 927k | (ignore_param(args), ...); | 116 | 927k | } |
void Botan::ignore_params<unsigned long const&, unsigned long const&>(unsigned long const&, unsigned long const&) Line | Count | Source | 114 | 11.9M | constexpr void ignore_params(T&&... args) { | 115 | 11.9M | (ignore_param(args), ...); | 116 | 11.9M | } |
void Botan::ignore_params<std::__1::vector<Botan::BigInt, std::__1::allocator<Botan::BigInt> >&>(std::__1::vector<Botan::BigInt, std::__1::allocator<Botan::BigInt> >&) Line | Count | Source | 114 | 11.7k | constexpr void ignore_params(T&&... args) { | 115 | 11.7k | (ignore_param(args), ...); | 116 | 11.7k | } |
Unexecuted instantiation: void Botan::ignore_params<Botan::SCAN_Name const&>(Botan::SCAN_Name const&) void Botan::ignore_params<std::__1::basic_string_view<char, std::__1::char_traits<char> >&>(std::__1::basic_string_view<char, std::__1::char_traits<char> >&) Line | Count | Source | 114 | 600 | constexpr void ignore_params(T&&... args) { | 115 | 600 | (ignore_param(args), ...); | 116 | 600 | } |
Unexecuted instantiation: void Botan::ignore_params<void*&, unsigned long&>(void*&, unsigned long&) void Botan::ignore_params<unsigned char const*&, unsigned long&>(unsigned char const*&, unsigned long&) Line | Count | Source | 114 | 234k | constexpr void ignore_params(T&&... args) { | 115 | 234k | (ignore_param(args), ...); | 116 | 234k | } |
void Botan::ignore_params<unsigned short const*&, unsigned long&>(unsigned short const*&, unsigned long&) Line | Count | Source | 114 | 141 | constexpr void ignore_params(T&&... args) { | 115 | 141 | (ignore_param(args), ...); | 116 | 141 | } |
Unexecuted instantiation: void Botan::ignore_params<std::__1::span<unsigned char const, 18446744073709551615ul>&>(std::__1::span<unsigned char const, 18446744073709551615ul>&) Unexecuted instantiation: void Botan::ignore_params<unsigned int const*&, unsigned long&>(unsigned int const*&, unsigned long&) void Botan::ignore_params<std::__1::span<unsigned char const, 18446744073709551615ul>&, std::__1::span<unsigned char const, 18446744073709551615ul>&>(std::__1::span<unsigned char const, 18446744073709551615ul>&, std::__1::span<unsigned char const, 18446744073709551615ul>&) Line | Count | Source | 114 | 164 | constexpr void ignore_params(T&&... args) { | 115 | 164 | (ignore_param(args), ...); | 116 | 164 | } |
void Botan::ignore_params<Botan::TLS::Session_Summary const&>(Botan::TLS::Session_Summary const&) Line | Count | Source | 114 | 82 | constexpr void ignore_params(T&&... args) { | 115 | 82 | (ignore_param(args), ...); | 116 | 82 | } |
void Botan::ignore_params<std::__1::vector<Botan::X509_Certificate, std::__1::allocator<Botan::X509_Certificate> > const&>(std::__1::vector<Botan::X509_Certificate, std::__1::allocator<Botan::X509_Certificate> > const&) Line | Count | Source | 114 | 32 | constexpr void ignore_params(T&&... args) { | 115 | 32 | (ignore_param(args), ...); | 116 | 32 | } |
void Botan::ignore_params<Botan::TLS::Certificate_Status_Request const&>(Botan::TLS::Certificate_Status_Request const&) Line | Count | Source | 114 | 32 | constexpr void ignore_params(T&&... args) { | 115 | 32 | (ignore_param(args), ...); | 116 | 32 | } |
Unexecuted instantiation: void Botan::ignore_params<char const*&>(char const*&) Unexecuted instantiation: void Botan::ignore_params<char const*&, unsigned char const*&, unsigned long&>(char const*&, unsigned char const*&, unsigned long&) Unexecuted instantiation: void Botan::ignore_params<std::__1::basic_string_view<char, std::__1::char_traits<char> >&, std::__1::span<unsigned char const, 18446744073709551615ul>&, std::__1::span<unsigned char const, 18446744073709551615ul>&>(std::__1::basic_string_view<char, std::__1::char_traits<char> >&, std::__1::span<unsigned char const, 18446744073709551615ul>&, std::__1::span<unsigned char const, 18446744073709551615ul>&) Unexecuted instantiation: void Botan::ignore_params<Botan::RandomNumberGenerator&>(Botan::RandomNumberGenerator&) Unexecuted instantiation: void Botan::ignore_params<Botan::Public_Key const&, Botan::Usage_Type&, std::__1::basic_string_view<char, std::__1::char_traits<char> >&, Botan::TLS::Policy const&>(Botan::Public_Key const&, Botan::Usage_Type&, std::__1::basic_string_view<char, std::__1::char_traits<char> >&, Botan::TLS::Policy const&) Unexecuted instantiation: void Botan::ignore_params<bool&>(bool&) Unexecuted instantiation: void Botan::ignore_params<short const*&, unsigned long&>(short const*&, unsigned long&) Unexecuted instantiation: void Botan::ignore_params<std::__1::basic_string_view<char, std::__1::char_traits<char> >&, Botan::EC_Group const&, Botan::RandomNumberGenerator&>(std::__1::basic_string_view<char, std::__1::char_traits<char> >&, Botan::EC_Group const&, Botan::RandomNumberGenerator&) Unexecuted instantiation: void Botan::ignore_params<std::__1::basic_string_view<char, std::__1::char_traits<char> >&, Botan::RandomNumberGenerator&, std::__1::basic_string_view<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >&>(std::__1::basic_string_view<char, std::__1::char_traits<char> >&, Botan::RandomNumberGenerator&, std::__1::basic_string_view<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >&) Unexecuted instantiation: void Botan::ignore_params<Botan::TLS::Client_Hello_12 const&>(Botan::TLS::Client_Hello_12 const&) Unexecuted instantiation: void Botan::ignore_params<Botan::X25519_PublicKey const*&>(Botan::X25519_PublicKey const*&) Unexecuted instantiation: void Botan::ignore_params<Botan::X448_PublicKey const*&>(Botan::X448_PublicKey const*&) void Botan::ignore_params<Botan::TLS::Protocol_Version&>(Botan::TLS::Protocol_Version&) Line | Count | Source | 114 | 18.0k | constexpr void ignore_params(T&&... args) { | 115 | 18.0k | (ignore_param(args), ...); | 116 | 18.0k | } |
void Botan::ignore_params<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 114 | 116 | constexpr void ignore_params(T&&... args) { | 115 | 116 | (ignore_param(args), ...); | 116 | 116 | } |
Unexecuted instantiation: void Botan::ignore_params<unsigned char const*&>(unsigned char const*&) Unexecuted instantiation: void Botan::ignore_params<unsigned char const*&, unsigned char const*&>(unsigned char const*&, unsigned char const*&) Unexecuted instantiation: void Botan::ignore_params<Botan::Classic_McEliece_GF const*&, unsigned long&>(Botan::Classic_McEliece_GF const*&, unsigned long&) Unexecuted instantiation: void Botan::ignore_params<bool const*&, unsigned long&>(bool const*&, unsigned long&) Unexecuted instantiation: void Botan::ignore_params<int const*&, unsigned long&>(int const*&, unsigned long&) Unexecuted instantiation: void Botan::ignore_params<bool const&>(bool const&) Unexecuted instantiation: void Botan::ignore_params<Botan::TLS::Connection_Side const&>(Botan::TLS::Connection_Side const&) |
117 | | |
118 | 273M | #define BOTAN_UNUSED Botan::ignore_params |
119 | | |
120 | | /* |
121 | | * Define Botan::assert_unreachable and BOTAN_ASSERT_UNREACHABLE |
122 | | * |
123 | | * This is intended to be used in the same situations as `std::unreachable()`; |
124 | | * a codepath that (should not) be reachable but where the compiler cannot |
125 | | * tell that it is unreachable. |
126 | | * |
127 | | * Unlike `std::unreachable()`, or equivalent compiler builtins like GCC's |
128 | | * `__builtin_unreachable`, this function is not UB. By default it will |
129 | | * throw an exception. If `BOTAN_TERMINATE_ON_ASSERTS` is defined, it will |
130 | | * instead print a message to stderr and abort. |
131 | | * |
132 | | * Due to this difference, and the fact that it is not inlined, calling |
133 | | * this is significantly more costly than using `std::unreachable`. |
134 | | */ |
135 | | [[noreturn]] void BOTAN_UNSTABLE_API assert_unreachable(const char* file, int line); |
136 | | |
137 | 0 | #define BOTAN_ASSERT_UNREACHABLE() Botan::assert_unreachable(__FILE__, __LINE__) |
138 | | |
139 | | } // namespace Botan |
140 | | |
141 | | #endif |