diff --git a/src/lib/utils/int_utils.h b/src/lib/utils/int_utils.h index 95b31e16db5..2c943f4d402 100644 --- a/src/lib/utils/int_utils.h +++ b/src/lib/utils/int_utils.h @@ -9,6 +9,7 @@ #include #include +#include #include namespace Botan { @@ -46,13 +47,12 @@ constexpr inline std::optional checked_mul(T a, T b) { return r; } -template -std::optional checked_cast(T input) { - const RT cast = static_cast(input); - if(static_cast(cast) != input) { +template +constexpr inline std::optional checked_cast(std::unsigned_integral auto input) { + if(std::numeric_limits::max() < input) { return {}; } - return cast; + return static_cast(input); } } // namespace Botan