Botan 3.6.0
Crypto and TLS for C&
Botan::BufferSlicer Class Referencefinal

#include <stl_util.h>

Public Member Functions

 BufferSlicer (std::span< const uint8_t > buffer)
 
template<concepts::contiguous_container ContainerT>
auto copy (const size_t count)
 
auto copy_as_secure_vector (const size_t count)
 
auto copy_as_vector (const size_t count)
 
void copy_into (std::span< uint8_t > sink)
 
bool empty () const
 
size_t remaining () const
 
void skip (const size_t count)
 
template<size_t count>
std::span< const uint8_t, count > take ()
 
std::span< const uint8_t > take (const size_t count)
 
template<concepts::contiguous_strong_type T>
StrongSpan< const Ttake (const size_t count)
 
uint8_t take_byte ()
 

Detailed Description

Helper class to ease unmarshalling of concatenated fixed-length values

Definition at line 84 of file stl_util.h.

Constructor & Destructor Documentation

◆ BufferSlicer()

Botan::BufferSlicer::BufferSlicer ( std::span< const uint8_t > buffer)
inline

Definition at line 86 of file stl_util.h.

86: m_remaining(buffer) {}

Member Function Documentation

◆ copy()

◆ copy_as_secure_vector()

auto Botan::BufferSlicer::copy_as_secure_vector ( const size_t count)
inline

Definition at line 96 of file stl_util.h.

96{ return copy<secure_vector<uint8_t>>(count); }
auto copy(const size_t count)
Definition stl_util.h:89

References copy().

Referenced by Botan::TLS::Session::decrypt().

◆ copy_as_vector()

auto Botan::BufferSlicer::copy_as_vector ( const size_t count)
inline

Definition at line 94 of file stl_util.h.

94{ return copy<std::vector<uint8_t>>(count); }

References copy().

Referenced by Botan::LMOTS_Signature::from_bytes_or_throw().

◆ copy_into()

void Botan::BufferSlicer::copy_into ( std::span< uint8_t > sink)
inline

Definition at line 120 of file stl_util.h.

120 {
121 const auto data = take(sink.size());
122 std::copy(data.begin(), data.end(), sink.begin());
123 }

References take().

Referenced by Botan::CRYSTALS::detail::as_byte_source().

◆ empty()

◆ remaining()

◆ skip()

void Botan::BufferSlicer::skip ( const size_t count)
inline

Definition at line 125 of file stl_util.h.

125{ take(count); }

References take().

Referenced by Botan::XMSS_PublicKey::XMSS_PublicKey().

◆ take() [1/3]

template<size_t count>
std::span< const uint8_t, count > Botan::BufferSlicer::take ( )
inline

Definition at line 106 of file stl_util.h.

106 {
107 BOTAN_STATE_CHECK(remaining() >= count);
108 auto result = m_remaining.first<count>();
109 m_remaining = m_remaining.subspan(count);
110 return result;
111 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41
size_t remaining() const
Definition stl_util.h:127

References BOTAN_STATE_CHECK, and remaining().

Referenced by copy(), copy_into(), skip(), take(), and take_byte().

◆ take() [2/3]

std::span< const uint8_t > Botan::BufferSlicer::take ( const size_t count)
inline

Definition at line 98 of file stl_util.h.

98 {
99 BOTAN_STATE_CHECK(remaining() >= count);
100 auto result = m_remaining.first(count);
101 m_remaining = m_remaining.subspan(count);
102 return result;
103 }

References BOTAN_STATE_CHECK, and remaining().

Referenced by Botan::Keccak_Permutation::absorb(), Botan::AlignmentBuffer< T, BLOCK_SIZE, FINAL_BLOCK_STRATEGY >::aligned_data_to_process(), Botan::SHA_256::compress_digest(), Botan::SHA_512::compress_digest(), Botan::SHA_512::compress_digest_bmi2(), Botan::SHA_256::compress_digest_x86_bmi2(), Botan::MD4::compress_n(), Botan::MD5::compress_n(), Botan::RIPEMD_160::compress_n(), Botan::SHA_1::compress_n(), Botan::SM3::compress_n(), Botan::Whirlpool::compress_n(), Botan::compute_root(), Botan::compute_root(), Botan::Kyber_Expanded_Keypair_Codec::decode_keypair(), Botan::Kyber_Algos::decompress_ciphertext(), Botan::TLS::Session::decrypt(), Botan::fors_public_key_from_signature(), Botan::FrodoKEM_PrivateKey::FrodoKEM_PrivateKey(), Botan::FrodoKEM_PublicKey::FrodoKEM_PublicKey(), Botan::HSS_LMS_PrivateKeyInternal::from_bytes_or_throw(), Botan::HSS_LMS_PublicKeyInternal::from_bytes_or_throw(), Botan::HSS_Signature::from_bytes_or_throw(), Botan::LMOTS_Signature::from_bytes_or_throw(), Botan::LMS_PublicKey::from_bytes_or_throw(), Botan::LMS_Signature::from_bytes_or_throw(), Botan::Sphincs_Hash_Functions::H_msg(), Botan::AlignmentBuffer< T, BLOCK_SIZE, FINAL_BLOCK_STRATEGY >::handle_unaligned_data(), Botan::ht_verify(), Botan::TLS::Hybrid_KEM_PublicKey::load_for_group(), Botan::AlignmentBuffer< T, BLOCK_SIZE, FINAL_BLOCK_STRATEGY >::next_aligned_block_to_process(), and Botan::wots_public_key_from_signature().

◆ take() [3/3]

template<concepts::contiguous_strong_type T>
StrongSpan< const T > Botan::BufferSlicer::take ( const size_t count)
inline

Definition at line 114 of file stl_util.h.

114 {
115 return StrongSpan<const T>(take(count));
116 }

References take().

◆ take_byte()

uint8_t Botan::BufferSlicer::take_byte ( )
inline

Definition at line 118 of file stl_util.h.

118{ return take(1)[0]; }

References take().

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


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