Botan 2.19.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 ()
 
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)
 
uint16_t get_uint16_t ()
 
uint32_t get_uint32_t ()
 
bool has_remaining () const
 
size_t read_so_far () const
 
size_t remaining_bytes () const
 
 TLS_Data_Reader (const char *type, const std::vector< 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,
const std::vector< 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) {}
MechanismType type

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

◆ get_byte()

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

◆ get_elem()

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

Definition at line 79 of file tls_reader.h.

80 {
81 assert_at_least(num_elems * sizeof(T));
82
83 Container result(num_elems);
84
85 for(size_t i = 0; i != num_elems; ++i)
86 result[i] = load_be<T>(&m_buf[m_offset], i);
87
88 m_offset += num_elems * sizeof(T);
89
90 return result;
91 }
fe T
Definition: ge.cpp:37

References T.

◆ get_fixed()

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

Definition at line 126 of file tls_reader.h.

127 {
128 return get_elem<T, std::vector<T>>(size);
129 }

Referenced by Botan::TLS::Certificate_Status_Request::Certificate_Status_Request(), Botan::TLS::Client_Hello::Client_Hello(), and Botan::TLS::Server_Hello::Server_Hello().

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

108 {
109 const size_t num_elems =
110 get_num_elems(len_bytes, sizeof(T), min_elems, max_elems);
111
112 return get_elem<T, std::vector<T>>(num_elems);
113 }

References T.

Referenced by Botan::TLS::Certificate_Req::Certificate_Req(), and Botan::TLS::Client_Hello::Client_Hello().

◆ get_remaining()

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

Definition at line 42 of file tls_reader.h.

43 {
44 return std::vector<uint8_t>(m_buf.begin() + m_offset, m_buf.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 115 of file tls_reader.h.

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

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::Server_Key_Exchange::Server_Key_Exchange(), and Botan::TLS::Server_Name_Indicator::Server_Name_Indicator().

◆ get_uint16_t()

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

◆ get_uint32_t()

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

Definition at line 53 of file tls_reader.h.

54 {
55 assert_at_least(4);
56 uint32_t result = make_uint32(m_buf[m_offset ], m_buf[m_offset+1],
57 m_buf[m_offset+2], m_buf[m_offset+3]);
58 m_offset += 4;
59 return result;
60 }
constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition: loadstor.h:67

References Botan::make_uint32().

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

◆ has_remaining()

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

Definition at line 40 of file tls_reader.h.

40{ return (remaining_bytes() > 0); }
size_t remaining_bytes() const
Definition: tls_reader.h:38

References remaining_bytes().

Referenced by assert_done(), Botan::TLS::Certificate_Req::Certificate_Req(), and Botan::TLS::Extensions::deserialize().

◆ read_so_far()

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

Definition at line 36 of file tls_reader.h.

36{ return m_offset; }

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

◆ remaining_bytes()

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

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