Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | List of all members
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< Tget_fixed (size_t size)
 
template<typename T >
std::vector< Tget_range (size_t len_bytes, size_t min_elems, size_t max_elems)
 
template<typename T >
std::vector< Tget_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 24 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 26 of file tls_reader.h.

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

Member Function Documentation

◆ assert_done()

void Botan::TLS::TLS_Data_Reader::assert_done ( ) const
inline

◆ discard_next()

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

Definition at line 47 of file tls_reader.h.

47 {
48 assert_at_least(bytes);
49 m_offset += bytes;
50 }

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

◆ get_byte()

uint8_t Botan::TLS::TLS_Data_Reader::get_byte ( )
inline

◆ get_data_read_so_far()

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

Definition at line 43 of file tls_reader.h.

43 {
44 return std::vector<uint8_t>(m_buf.begin(), m_buf.begin() + m_offset);
45 }

◆ get_elem()

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

Definition at line 86 of file tls_reader.h.

86 {
87 assert_at_least(num_elems * sizeof(T));
88
89 Container result(num_elems);
90
91 for(size_t i = 0; i != num_elems; ++i) {
92 result[i] = load_be<T>(&m_buf[m_offset], i);
93 }
94
95 m_offset += num_elems * sizeof(T);
96
97 return result;
98 }
FE_25519 T
Definition ge.cpp:34

References T.

◆ 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 112 of file tls_reader.h.

112 {
113 const size_t num_elems = get_num_elems(len_bytes, sizeof(T), min_elems, max_elems);
114
115 return get_elem<T, std::vector<T>>(num_elems);
116 }

References T.

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

◆ get_remaining()

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

Definition at line 41 of file tls_reader.h.

41{ return std::vector<uint8_t>(m_buf.begin() + m_offset, m_buf.end()); }

◆ 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 118 of file tls_reader.h.

118 {
119 std::vector<uint8_t> v = get_range_vector<uint8_t>(len_bytes, min_bytes, max_bytes);
120
121 return std::string(cast_uint8_ptr_to_char(v.data()), v.size());
122 }
const char * cast_uint8_ptr_to_char(const uint8_t *b)
Definition mem_ops.h:279

References Botan::cast_uint8_ptr_to_char().

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()

std::vector< uint8_t > Botan::TLS::TLS_Data_Reader::get_tls_length_value ( size_t len_bytes)
inline

◆ get_uint16_t()

uint16_t Botan::TLS::TLS_Data_Reader::get_uint16_t ( )
inline

◆ get_uint24_t()

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

Definition at line 59 of file tls_reader.h.

59 {
60 assert_at_least(3);
61 uint32_t result = make_uint32(0, m_buf[m_offset], m_buf[m_offset + 1], m_buf[m_offset + 2]);
62 m_offset += 3;
63 return result;
64 }
constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition loadstor.h:100

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 52 of file tls_reader.h.

52 {
53 assert_at_least(4);
54 uint32_t result = make_uint32(m_buf[m_offset], m_buf[m_offset + 1], m_buf[m_offset + 2], m_buf[m_offset + 3]);
55 m_offset += 4;
56 return result;
57 }

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()

bool Botan::TLS::TLS_Data_Reader::has_remaining ( ) const
inline

◆ peek_uint16_t()

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

Definition at line 73 of file tls_reader.h.

73 {
74 assert_at_least(2);
75 return make_uint16(m_buf[m_offset], m_buf[m_offset + 1]);
76 }

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()

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

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