Botan 3.11.0
Crypto and TLS for C&
Botan::ranges Namespace Reference

Concepts

concept  contiguous_output_range
concept  contiguous_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 (const R0 &r0, const Rs &... rs)
template<size_t expected, spanable_range R>
constexpr void assert_exact_byte_length (const R &r)
void BOTAN_UNSTABLE_API memory_region_size_violation ()
constexpr size_t size_bytes (const spanable_range auto &r)

Detailed Description

(C) 2023 Jack Lloyd 2023 René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

Function Documentation

◆ assert_equal_byte_lengths()

template<spanable_range R0, spanable_range... Rs>
requires (sizeof...(Rs) > 0)
void Botan::ranges::assert_equal_byte_lengths ( const R0 & r0,
const 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 98 of file range_concepts.h.

100{
101 const std::span s0{r0};
102
103 if constexpr(statically_spanable_range<R0>) {
104 constexpr size_t expected_size = s0.size_bytes();
106 } else {
107 const size_t expected_size = s0.size_bytes();
108 const bool correct_size =
109 ((std::span<const std::ranges::range_value_t<Rs>>{rs}.size_bytes() == expected_size) && ...);
110
111 if(!correct_size) {
113 }
114 }
115}
void BOTAN_UNSTABLE_API memory_region_size_violation()
Definition assert.cpp:32
constexpr void assert_exact_byte_length(const R &r)

References assert_equal_byte_lengths(), assert_exact_byte_length(), and memory_region_size_violation().

Referenced by assert_equal_byte_lengths(), 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>
void Botan::ranges::assert_exact_byte_length ( const 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 77 of file range_concepts.h.

77 {
78 const std::span s{r};
79 if constexpr(statically_spanable_range<R>) {
80 static_assert(s.size_bytes() == expected, "memory region does not have expected byte lengths");
81 } else {
82 if(s.size_bytes() != expected) {
84 }
85 }
86}

References assert_exact_byte_length(), and memory_region_size_violation().

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

◆ memory_region_size_violation()

void Botan::ranges::memory_region_size_violation ( )

Throws an exception indicating that the attempted read or write was invalid

Definition at line 32 of file assert.cpp.

32 {
33 throw Invalid_Argument("Memory regions did not have expected byte lengths");
34}

Referenced by assert_equal_byte_lengths(), and assert_exact_byte_length().

◆ size_bytes()

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

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

Definition at line 59 of file range_concepts.h.

59 {
60 return std::span{r}.size_bytes();
61}

References size_bytes().

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