Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | List of all members
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 142 of file stl_util.h.

Constructor & Destructor Documentation

◆ BufferSlicer()

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

Definition at line 144 of file stl_util.h.

144: m_remaining(buffer) {}

Member Function Documentation

◆ copy()

template<concepts::contiguous_container ContainerT>
auto Botan::BufferSlicer::copy ( const size_t count)
inline

Definition at line 147 of file stl_util.h.

147 {
148 const auto result = take(count);
149 return ContainerT(result.begin(), result.end());
150 }
std::span< const uint8_t, count > take()
Definition stl_util.h:164

References take().

Referenced by Botan::FrodoKEM_PrivateKey::FrodoKEM_PrivateKey(), Botan::FrodoKEM_PublicKey::FrodoKEM_PublicKey(), and Botan::Sphincs_Hash_Functions::H_msg().

◆ copy_as_secure_vector()

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

Definition at line 154 of file stl_util.h.

154{ return copy<secure_vector<uint8_t>>(count); }

Referenced by Botan::TLS::Session::decrypt(), Botan::Kyber_PrivateKey::Kyber_PrivateKey(), and Botan::XMSS_PublicKey::XMSS_PublicKey().

◆ copy_as_vector()

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

Definition at line 152 of file stl_util.h.

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

Referenced by Botan::Kyber_PublicKey::initialize_from_encoding(), and Botan::Kyber_PrivateKey::Kyber_PrivateKey().

◆ copy_into()

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

Definition at line 178 of file stl_util.h.

178 {
179 const auto data = take(sink.size());
180 std::copy(data.begin(), data.end(), sink.begin());
181 }

References take().

◆ empty()

bool Botan::BufferSlicer::empty ( ) const
inline

◆ remaining()

size_t Botan::BufferSlicer::remaining ( ) const
inline

◆ skip()

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

Definition at line 183 of file stl_util.h.

183{ take(count); }

References take().

Referenced by Botan::Kyber_PrivateKey::Kyber_PrivateKey(), and 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 164 of file stl_util.h.

164 {
165 BOTAN_STATE_CHECK(remaining() >= count);
166 auto result = m_remaining.first<count>();
167 m_remaining = m_remaining.subspan(count);
168 return result;
169 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41
size_t remaining() const
Definition stl_util.h:185

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

◆ take() [3/3]

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

Definition at line 172 of file stl_util.h.

172 {
173 return StrongSpan<const T>(take(count));
174 }

References take().

◆ take_byte()

uint8_t Botan::BufferSlicer::take_byte ( )
inline

Definition at line 176 of file stl_util.h.

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

References take().

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


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