Botan 3.9.0
Crypto and TLS for C&
Botan::TLS::TLS_Data_Reader Class Referencefinal

#include <tls_reader.h>

Public Member Functions

void assert_done () const
void discard_next (size_t bytes)
uint8_t get_byte ()
std::vector< uint8_t > get_data_read_so_far ()
template<typename T, typename Container>
Container get_elem (size_t num_elems)
template<typename T>
std::vector< T > get_fixed (size_t size)
template<typename T>
std::vector< T > get_range (size_t len_bytes, size_t min_elems, size_t max_elems)
template<typename T>
std::vector< T > get_range_vector (size_t len_bytes, size_t min_elems, size_t max_elems)
std::vector< uint8_t > get_remaining ()
std::string get_string (size_t len_bytes, size_t min_bytes, size_t max_bytes)
std::vector< uint8_t > get_tls_length_value (size_t len_bytes)
uint16_t get_uint16_t ()
uint32_t get_uint24_t ()
uint32_t get_uint32_t ()
bool has_remaining () const
uint16_t peek_uint16_t () const
size_t read_so_far () const
size_t remaining_bytes () const
 TLS_Data_Reader (const char *type, std::span< const uint8_t > buf_in)

Detailed Description

Helper class for decoding TLS protocol messages

Definition at line 25 of file tls_reader.h.

Constructor & Destructor Documentation

◆ TLS_Data_Reader()

Botan::TLS::TLS_Data_Reader::TLS_Data_Reader ( const char * type,
std::span< const uint8_t > buf_in )
inline

Definition at line 27 of file tls_reader.h.

27 :
28 m_typename(type), m_buf(buf_in), m_offset(0) {}

Member Function Documentation

◆ assert_done()

◆ discard_next()

void Botan::TLS::TLS_Data_Reader::discard_next ( size_t bytes)
inline

Definition at line 52 of file tls_reader.h.

52 {
53 assert_at_least(bytes);
54 m_offset += bytes;
55 }

Referenced by Botan::TLS::Server_Name_Indicator::Server_Name_Indicator(), and Botan::TLS::Supported_Point_Formats::Supported_Point_Formats().

◆ get_byte()

◆ get_data_read_so_far()

std::vector< uint8_t > Botan::TLS::TLS_Data_Reader::get_data_read_so_far ( )
inline

Definition at line 47 of file tls_reader.h.

47 {
48 std::span first = m_buf.first(m_offset);
49 return std::vector<uint8_t>(first.begin(), first.end());
50 }

◆ get_elem()

template<typename T, typename Container>
Container Botan::TLS::TLS_Data_Reader::get_elem ( size_t num_elems)
inline

Definition at line 91 of file tls_reader.h.

91 {
92 assert_at_least(num_elems * sizeof(T));
93
94 Container result(num_elems);
95
96 for(size_t i = 0; i != num_elems; ++i) {
97 result[i] = load_be<T>(&m_buf[m_offset], i);
98 }
99
100 m_offset += num_elems * sizeof(T);
101
102 return result;
103 }
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504

References Botan::load_be().

Referenced by get_fixed(), get_range(), and get_range_vector().

◆ get_fixed()

template<typename T>
std::vector< T > Botan::TLS::TLS_Data_Reader::get_fixed ( size_t size)
inline

◆ get_range()

template<typename T>
std::vector< T > Botan::TLS::TLS_Data_Reader::get_range ( size_t len_bytes,
size_t min_elems,
size_t max_elems )
inline

◆ get_range_vector()

template<typename T>
std::vector< T > Botan::TLS::TLS_Data_Reader::get_range_vector ( size_t len_bytes,
size_t min_elems,
size_t max_elems )
inline

Definition at line 117 of file tls_reader.h.

117 {
118 const size_t num_elems = get_num_elems(len_bytes, sizeof(T), min_elems, max_elems);
119
120 return get_elem<T, std::vector<T>>(num_elems);
121 }

References get_elem().

Referenced by Botan::TLS::Certificate_Request_12::Certificate_Request_12(), and get_string().

◆ get_remaining()

std::vector< uint8_t > Botan::TLS::TLS_Data_Reader::get_remaining ( )
inline

Definition at line 42 of file tls_reader.h.

42 {
43 std::span rest = m_buf.subspan(m_offset);
44 return std::vector<uint8_t>(rest.begin(), rest.end());
45 }

◆ get_string()

std::string Botan::TLS::TLS_Data_Reader::get_string ( size_t len_bytes,
size_t min_bytes,
size_t max_bytes )
inline

Definition at line 123 of file tls_reader.h.

123 {
124 std::vector<uint8_t> v = get_range_vector<uint8_t>(len_bytes, min_bytes, max_bytes);
125 return bytes_to_string(v);
126 }
std::vector< T > get_range_vector(size_t len_bytes, size_t min_elems, size_t max_elems)
Definition tls_reader.h:117
std::string bytes_to_string(std::span< const uint8_t > bytes)
Definition mem_utils.h:45

References Botan::bytes_to_string(), and get_range_vector().

Referenced by Botan::TLS::Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and Botan::TLS::Server_Name_Indicator::Server_Name_Indicator().

◆ get_tls_length_value()

◆ get_uint16_t()

◆ get_uint24_t()

uint32_t Botan::TLS::TLS_Data_Reader::get_uint24_t ( )
inline

Definition at line 64 of file tls_reader.h.

64 {
65 assert_at_least(3);
66 uint32_t result = make_uint32(0, m_buf[m_offset], m_buf[m_offset + 1], m_buf[m_offset + 2]);
67 m_offset += 3;
68 return result;
69 }
constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition loadstor.h:104

References Botan::make_uint32().

Referenced by Botan::TLS::Certificate_13::Certificate_13().

◆ get_uint32_t()

uint32_t Botan::TLS::TLS_Data_Reader::get_uint32_t ( )
inline

Definition at line 57 of file tls_reader.h.

57 {
58 assert_at_least(4);
59 uint32_t result = make_uint32(m_buf[m_offset], m_buf[m_offset + 1], m_buf[m_offset + 2], m_buf[m_offset + 3]);
60 m_offset += 4;
61 return result;
62 }

References Botan::make_uint32().

Referenced by Botan::TLS::EarlyDataIndication::EarlyDataIndication(), Botan::TLS::New_Session_Ticket_12::New_Session_Ticket_12(), Botan::TLS::New_Session_Ticket_13::New_Session_Ticket_13(), and Botan::TLS::PSK::PSK().

◆ has_remaining()

◆ peek_uint16_t()

uint16_t Botan::TLS::TLS_Data_Reader::peek_uint16_t ( ) const
inline

Definition at line 78 of file tls_reader.h.

78 {
79 assert_at_least(2);
80 return make_uint16(m_buf[m_offset], m_buf[m_offset + 1]);
81 }

References Botan::make_uint16().

Referenced by Botan::TLS::Certificate_13::Certificate_Entry::Certificate_Entry().

◆ read_so_far()

size_t Botan::TLS::TLS_Data_Reader::read_so_far ( ) const
inline

◆ remaining_bytes()


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