Botan 3.5.0
Crypto and TLS for C&
loadstor.h File Reference

This header contains various helper functions to load and store unsigned integers in big- or little-endian byte order. More...

#include <botan/concepts.h>
#include <botan/mem_ops.h>
#include <botan/types.h>
#include <botan/internal/bswap.h>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  Botan
 
namespace  Botan::detail
 

Concepts

concept  Botan::detail::unsigned_integralish
 

Enumerations

enum class  Botan::detail::Endianness : bool { Botan::detail::Big , Botan::detail::Little }
 

Functions

template<Endianness endianness, unsigned_integralish T>
size_t Botan::detail::copy_out_any_word_aligned_portion (std::span< uint8_t > &out, std::span< const T > &in)
 
template<ranges::spanable_range InR>
void Botan::copy_out_be (std::span< uint8_t > out, InR &&in)
 
template<ranges::spanable_range InR>
void Botan::copy_out_le (std::span< uint8_t > out, InR &&in)
 
template<Endianness endianness, std::unsigned_integral OutT, ranges::contiguous_range< uint8_t > InR>
constexpr OutT Botan::detail::fallback_load_any (InR &&in_range)
 
template<Endianness endianness, std::unsigned_integral InT, ranges::contiguous_output_range< uint8_t > OutR>
constexpr void Botan::detail::fallback_store_any (InT in, OutR &&out_range)
 
template<size_t B, typename T >
requires (B < sizeof(T))
constexpr uint8_t Botan::get_byte (T input)
 
template<typename T >
constexpr uint8_t Botan::get_byte_var (size_t byte_num, T input)
 
constexpr bool Botan::detail::is_native (Endianness endianness)
 
constexpr bool Botan::detail::is_opposite (Endianness endianness)
 
template<Endianness endianness, unsigned_integralish OutT>
constexpr OutT Botan::detail::load_any (const uint8_t in[], size_t off)
 
template<Endianness endianness, typename OutT , unsigned_integralish... Ts>
requires (sizeof...(Ts) > 0 && all_same_v<Ts...> && ((std::same_as<AutoDetect, OutT> && all_same_v<Ts...>) || (unsigned_integralish<OutT> && all_same_v<OutT, Ts...>)))
constexpr void Botan::detail::load_any (const uint8_t in[], Ts &... outs)
 
template<Endianness endianness, typename OutT , ranges::contiguous_range< uint8_t > InR, unsigned_integralish... Ts>
requires (sizeof...(Ts) > 0) && ((std::same_as<AutoDetect, OutT> && all_same_v<Ts...>) || (unsigned_integralish<OutT> && all_same_v<OutT, Ts...>))
constexpr void Botan::detail::load_any (InR &&in, Ts &... outs)
 
template<Endianness endianness, std::unsigned_integral OutT, ranges::contiguous_range< uint8_t > InR>
constexpr OutT Botan::detail::load_any (InR &&in_range)
 
template<Endianness endianness, typename OutT , ranges::contiguous_range< uint8_t > InR>
requires (std::is_enum_v<OutT> && std::unsigned_integral<std::underlying_type_t<OutT>>)
constexpr OutT Botan::detail::load_any (InR &&in_range)
 
template<Endianness endianness, typename OutT , ranges::contiguous_range< uint8_t > InR>
requires (std::same_as<AutoDetect, OutT> || ((ranges::statically_spanable_range<OutT> || concepts::resizable_container<OutT>) && unsigned_integralish<typename OutT::value_type>))
constexpr auto Botan::detail::load_any (InR &&in_range)
 
template<Endianness endianness, typename OutT , ranges::contiguous_output_range OutR, ranges::contiguous_range< uint8_t > InR>
requires (unsigned_integralish<std::ranges::range_value_t<OutR>> && (std::same_as<AutoDetect, OutT> || std::same_as<OutT, std::ranges::range_value_t<OutR>>))
constexpr void Botan::detail::load_any (OutR &&out, InR &&in)
 
template<Endianness endianness, typename OutT , unsigned_integralish T>
requires (std::same_as<AutoDetect, OutT> || std::same_as<T, OutT>)
constexpr void Botan::detail::load_any (T out[], const uint8_t in[], size_t count)
 
template<typename OutT = detail::AutoDetect, typename... ParamTs>
constexpr auto Botan::load_be (ParamTs &&... params)
 
template<typename OutT = detail::AutoDetect, typename... ParamTs>
constexpr auto Botan::load_le (ParamTs &&... params)
 
constexpr uint16_t Botan::make_uint16 (uint8_t i0, uint8_t i1)
 
constexpr uint32_t Botan::make_uint32 (uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
 
constexpr uint64_t Botan::make_uint64 (uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3, uint8_t i4, uint8_t i5, uint8_t i6, uint8_t i7)
 
template<Endianness endianness>
constexpr bool Botan::detail::native_endianness_is_unknown ()
 
template<Endianness endianness, typename OutR , ranges::spanable_range InR>
requires (std::same_as<AutoDetect, OutR> || (ranges::statically_spanable_range<OutR> && std::default_initializable<OutR>) || concepts::resizable_byte_buffer<OutR>)
constexpr auto Botan::detail::store_any (InR &&in_range)
 
template<Endianness endianness, std::unsigned_integral InT, ranges::contiguous_output_range< uint8_t > OutR>
constexpr void Botan::detail::store_any (InT in, OutR &&out_range)
 
template<Endianness endianness, typename InT , ranges::contiguous_output_range< uint8_t > OutR>
requires (std::is_enum_v<InT> && std::unsigned_integral<std::underlying_type_t<InT>>)
constexpr void Botan::detail::store_any (InT in, OutR &&out_range)
 
template<Endianness endianness, typename InT , ranges::contiguous_output_range< uint8_t > OutR, ranges::spanable_range InR>
requires (std::same_as<AutoDetect, InT> || std::same_as<InT, std::ranges::range_value_t<InR>>)
constexpr void Botan::detail::store_any (OutR &&out, InR &&in)
 
template<Endianness endianness, typename InT , ranges::contiguous_output_range< uint8_t > OutR, unsigned_integralish... Ts>
requires (sizeof...(Ts) > 0) && ((std::same_as<AutoDetect, InT> && all_same_v<Ts...>) || (unsigned_integralish<InT> && all_same_v<InT, Ts...>))
constexpr void Botan::detail::store_any (OutR &&out, Ts... ins)
 
template<Endianness endianness, typename InT , unsigned_integralish T, ranges::contiguous_output_range< uint8_t > OutR>
requires std::same_as<AutoDetect, InT>
constexpr void Botan::detail::store_any (T in, OutR &&out_range)
 
template<Endianness endianness, typename InT , unsigned_integralish T>
requires (std::same_as<AutoDetect, InT> || std::same_as<T, InT>)
constexpr void Botan::detail::store_any (T in, uint8_t out[])
 
template<Endianness endianness, typename OutR , unsigned_integralish... Ts>
requires all_same_v<Ts...>
constexpr auto Botan::detail::store_any (Ts... ins)
 
template<Endianness endianness, typename InT , unsigned_integralish T0, unsigned_integralish... Ts>
requires (std::same_as<AutoDetect, InT> || std::same_as<T0, InT>) && all_same_v<T0, Ts...>
constexpr void Botan::detail::store_any (uint8_t out[], T0 in0, Ts... ins)
 
template<typename ModifierT = detail::AutoDetect, typename... ParamTs>
constexpr auto Botan::store_be (ParamTs &&... params)
 
template<typename ModifierT = detail::AutoDetect, typename... ParamTs>
constexpr auto Botan::store_le (ParamTs &&... params)
 

Detailed Description

This header contains various helper functions to load and store unsigned integers in big- or little-endian byte order.

Internal Header.

Storing integer values in various ways (same for BE and LE):

std::array<uint8_t, 8> bytes = store_le(some_uint64);
std::array<uint8_t, 12> bytes = store_le(some_uint32_1, some_uint32_2, some_uint32_3, ...);
auto bytes = store_le<std::vector<uint8_t>>(some_uint64);
auto bytes = store_le<MyContainerStrongType>(some_uint64);
auto bytes = store_le<std::vector<uint8_t>>(vector_of_ints);
auto bytes = store_le<secure_vector<uint8_t>>(some_uint32_1, some_uint32_2, some_uint32_3, ...);
store_le(bytes, some_uint64);
store_le(concatenated_bytes, some_uint64_1, some_uint64_2, some_uint64_3, ...);
store_le(concatenated_bytes, vector_of_ints);
copy_out_le(short_concated_bytes, vector_of_ints); // stores as many bytes as required in the output buffer

Loading integer values in various ways (same for BE and LE):

uint64_t some_uint64 = load_le(bytes_8);
auto some_int32s = load_le<std::vector<uint32_t>>(concatenated_bytes);
auto some_int32s = load_le<std::vector<MyIntStrongType>>(concatenated_bytes);
auto some_int32s = load_le(some_strong_typed_bytes);
auto strong_int = load_le<MyStrongTypedInteger>(concatenated_bytes);
load_le(concatenated_bytes, out_some_uint64);
load_le(concatenated_bytes, out_some_uint64_1, out_some_uint64_2, out_some_uint64_3, ...);
load_le(out_vector_of_ints, concatenated_bytes);

Definition in file loadstor.h.