Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::BufferStuffer Class Reference

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 ()
 
constexpr std::span< uint8_t > next (size_t bytes)
 
template<concepts::contiguous_strong_type StrongT>
StrongSpan< StrongT > 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 200 of file stl_util.h.

Constructor & Destructor Documentation

◆ BufferStuffer()

constexpr Botan::BufferStuffer::BufferStuffer ( std::span< uint8_t > buffer)
inlineconstexpr

Definition at line 202 of file stl_util.h.

202: m_buffer(buffer) {}

Member Function Documentation

◆ append() [1/2]

constexpr void Botan::BufferStuffer::append ( std::span< const uint8_t > buffer)
inlineconstexpr

Definition at line 235 of file stl_util.h.

235 {
236 auto sink = next(buffer.size());
237 std::copy(buffer.begin(), buffer.end(), sink.begin());
238 }
constexpr std::span< uint8_t, bytes > next()
Definition stl_util.h:217

References next().

Referenced by Botan::EME_PKCS1v15::pad(), and Botan::sign_message().

◆ append() [2/2]

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

Definition at line 240 of file stl_util.h.

240 {
241 auto sink = next(repeat);
242 std::fill(sink.begin(), sink.end(), b);
243 }

References next().

◆ full()

constexpr bool Botan::BufferStuffer::full ( ) const
inlineconstexpr

◆ next() [1/3]

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

Definition at line 217 of file stl_util.h.

217 {
218 BOTAN_STATE_CHECK(m_buffer.size() >= bytes);
219
220 auto result = m_buffer.first<bytes>();
221 m_buffer = m_buffer.subspan(bytes);
222 return result;
223 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41

References BOTAN_STATE_CHECK.

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

◆ next() [2/3]

constexpr std::span< uint8_t > Botan::BufferStuffer::next ( size_t bytes)
inlineconstexpr
Returns
a span for the next bytes bytes in the concatenated buffer. Checks that the buffer is not exceded.

Definition at line 208 of file stl_util.h.

208 {
209 BOTAN_STATE_CHECK(m_buffer.size() >= bytes);
210
211 auto result = m_buffer.first(bytes);
212 m_buffer = m_buffer.subspan(bytes);
213 return result;
214 }

References BOTAN_STATE_CHECK.

Referenced by Botan::create_aes_row_generator(), Botan::fors_public_key_from_signature(), Botan::fors_sign_and_pkgen(), Botan::ht_sign(), Botan::Keccak_Permutation::squeeze(), Botan::wots_public_key_from_signature(), Botan::wots_sign_and_pkgen(), and Botan::xmss_sign_and_pkgen().

◆ next() [3/3]

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

Definition at line 226 of file stl_util.h.

226 {
227 return StrongSpan<StrongT>(next(bytes));
228 }

References next().

◆ next_byte()

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

Definition at line 233 of file stl_util.h.

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

References next().

Referenced by Botan::Keccak_Permutation::squeeze().

◆ remaining_capacity()

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

Definition at line 247 of file stl_util.h.

247{ return m_buffer.size(); }

Referenced by Botan::Keccak_Permutation::squeeze(), and Botan::xmss_sign_and_pkgen().


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