7#ifndef BOTAN_INT_UTILS_H_
8#define BOTAN_INT_UTILS_H_
10#include <botan/concepts.h>
11#include <botan/exceptn.h>
12#include <botan/types.h>
18template <std::
unsigned_
integral T>
27template <std::unsigned_integral
T, std::unsigned_integral... Ts>
28 requires all_same_v<
T, Ts...>
37template <std::
unsigned_
integral T>
42 const T r = (1U * a) * b;
45 if(a != 0 && r / a != b) {
56template <
int_or_strong_type T>
59template <
int_or_strong_type T>
60 requires std::integral<T>
65template <
int_or_strong_type T>
68 using type =
typename T::wrapped_type;
71template <
int_or_strong_type T>
74template <
int_or_strong_type T>
76 if constexpr(std::integral<T>) {
83template <
int_or_strong_type T>
85 if constexpr(std::integral<T>) {
94template <detail::
int_or_strong_type RT,
typename ExceptionType, detail::
int_or_strong_type AT>
100 const auto unwrapped_result =
static_cast<unwrapped_result_type
>(unwrapped_input);
101 if(unwrapped_input !=
static_cast<unwrapped_input_type
>(unwrapped_result)) [[unlikely]] {
102 throw ExceptionType(error_msg_on_fail);
108template <detail::
int_or_strong_type RT, detail::
int_or_strong_type AT>
113#define BOTAN_CHECKED_ADD(x, y) checked_add(x, y, __FILE__, __LINE__)
114#define BOTAN_CHECKED_MUL(x, y) checked_mul(x, y)
constexpr auto unwrap(T t) -> unwrap_type_t< T >
constexpr auto wrap(unwrap_type_t< T > t) -> T
typename unwrap_type< T >::type unwrap_type_t
constexpr std::optional< T > checked_add(T a, T b)
constexpr RT checked_cast_to(AT i)
constexpr RT checked_cast_to_or_throw(AT i, std::string_view error_msg_on_fail)
constexpr std::optional< T > checked_mul(T a, T b)