Botan 3.10.0
Crypto and TLS for C&
Botan::BufferStuffer Class Referencefinal

Helper class to ease in-place marshalling of concatenated fixed-length values. More...

#include <stl_util.h>

Public Member Functions

constexpr void append (std::span< const uint8_t > buffer)
constexpr void append (uint8_t b, size_t repeat=1)
constexpr BufferStuffer (std::span< uint8_t > buffer)
constexpr bool full () const
template<size_t bytes>
constexpr std::span< uint8_t, bytes > next ()
template<concepts::contiguous_strong_type StrongT>
StrongSpan< StrongT > next (size_t bytes)
constexpr std::span< uint8_t > next (size_t bytes)
constexpr uint8_t & next_byte ()
constexpr size_t remaining_capacity () const

Detailed Description

Helper class to ease in-place marshalling of concatenated fixed-length values.

The size of the final buffer must be known from the start, reallocations are not performed.

Definition at line 133 of file stl_util.h.

Constructor & Destructor Documentation

◆ BufferStuffer()

Botan::BufferStuffer::BufferStuffer ( std::span< uint8_t > buffer)
inlineexplicitconstexpr

Definition at line 135 of file stl_util.h.

135: m_buffer(buffer) {}

Member Function Documentation

◆ append() [1/2]

◆ append() [2/2]

void Botan::BufferStuffer::append ( uint8_t b,
size_t repeat = 1 )
inlineconstexpr

Definition at line 173 of file stl_util.h.

173 {
174 auto sink = next(repeat);
175 std::fill(sink.begin(), sink.end(), b);
176 }

References next().

◆ full()

◆ next() [1/3]

template<size_t bytes>
std::span< uint8_t, bytes > Botan::BufferStuffer::next ( )
inlineconstexpr

Definition at line 150 of file stl_util.h.

150 {
151 BOTAN_STATE_CHECK(m_buffer.size() >= bytes);
152
153 auto result = m_buffer.first<bytes>();
154 m_buffer = m_buffer.subspan(bytes);
155 return result;
156 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_STATE_CHECK.

Referenced by append(), append(), next(), and next_byte().

◆ next() [2/3]

template<concepts::contiguous_strong_type StrongT>
StrongSpan< StrongT > Botan::BufferStuffer::next ( size_t bytes)
inline

Definition at line 159 of file stl_util.h.

159 {
160 return StrongSpan<StrongT>(next(bytes));
161 }

References next().

◆ next() [3/3]

◆ next_byte()

uint8_t & Botan::BufferStuffer::next_byte ( )
inlineconstexpr
Returns
a reference to the next single byte in the buffer

Definition at line 166 of file stl_util.h.

166{ return next(1)[0]; }

References next().

◆ remaining_capacity()

size_t Botan::BufferStuffer::remaining_capacity ( ) const
inlineconstexpr

Definition at line 180 of file stl_util.h.

180{ return m_buffer.size(); }

Referenced by Botan::create_aes_row_generator(), Botan::CRYSTALS::pack(), Botan::TPM2::Context::vendor(), and Botan::xmss_sign_and_pkgen().


The documentation for this class was generated from the following file: