Botan 3.4.0
Crypto and TLS for C&
Concepts | Functions
Botan::ranges Namespace Reference

Concepts

concept  contiguous_range
 
concept  contiguous_output_range
 
concept  spanable_range
 
concept  statically_spanable_range
 

Functions

template<spanable_range R0, spanable_range... Rs>
requires (sizeof...(Rs) > 0)
constexpr void assert_equal_byte_lengths (R0 &&r0, Rs &&... rs)
 
template<size_t expected, spanable_range R>
constexpr void assert_exact_byte_length (R &&r)
 
constexpr size_t size_bytes (spanable_range auto &&r)
 

Function Documentation

◆ assert_equal_byte_lengths()

template<spanable_range R0, spanable_range... Rs>
requires (sizeof...(Rs) > 0)
constexpr void Botan::ranges::assert_equal_byte_lengths ( R0 && r0,
Rs &&... rs )
inlineconstexpr

Check that a list of ranges (in r0 and rs) all have the same byte lengths. If the first range's extent is known at compile time, this will be a static check for all other ranges whose extents are known at compile time, otherwise a runtime argument check will be added.

Exceptions
Invalid_Argumentif any range has a dynamic extent and not all ranges feature the same byte length.

Definition at line 116 of file concepts.h.

118{
119 const std::span s0{r0};
120
121 if constexpr(statically_spanable_range<R0>) {
122 constexpr size_t expected_size = s0.size_bytes();
123 (assert_exact_byte_length<expected_size>(rs), ...);
124 } else {
125 const size_t expected_size = s0.size_bytes();
126 BOTAN_ARG_CHECK(((std::span<const std::ranges::range_value_t<Rs>>{rs}.size_bytes() == expected_size) && ...),
127 "memory regions don't have equal lengths");
128 }
129}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29

References BOTAN_ARG_CHECK.

Referenced by Botan::copy_mem(), Botan::detail::load_any(), Botan::detail::store_any(), Botan::typecast_copy(), Botan::xor_buf(), and Botan::xor_buf().

◆ assert_exact_byte_length()

template<size_t expected, spanable_range R>
constexpr void Botan::ranges::assert_exact_byte_length ( R && r)
inlineconstexpr

Check that a given range r has a certain statically-known byte length. If the range's extent is known at compile time, this is a static check, otherwise a runtime argument check will be added.

Exceptions
Invalid_Argumentif range r has a dynamic extent and does not feature the expected byte length.

Definition at line 97 of file concepts.h.

97 {
98 const std::span s{r};
99 if constexpr(statically_spanable_range<R>) {
100 static_assert(s.size_bytes() == expected, "memory region does not have expected byte lengths");
101 } else {
102 BOTAN_ASSERT(s.size_bytes() == expected, "memory region does not have expected byte lengths");
103 }
104}
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:50

References BOTAN_ASSERT.

Referenced by Botan::detail::load_any(), and Botan::detail::store_any().

◆ size_bytes()

constexpr size_t Botan::ranges::size_bytes ( spanable_range auto && r)
inlineconstexpr

Find the length in bytes of a given contiguous range r.

Definition at line 84 of file concepts.h.

84 {
85 return std::span{r}.size_bytes();
86}

Referenced by Botan::clear_mem(), Botan::copy_mem(), Botan::secure_scrub_memory(), and Botan::typecast_copy().