Botan  2.7.0
Crypto and TLS for C++11
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

Definition at line 30 of file tls_reader.h.

References has_remaining().

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

31  {
32  if(has_remaining())
33  throw decode_error("Extra bytes at end of message");
34  }
bool has_remaining() const
Definition: tls_reader.h:40

◆ 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.

References T.

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

◆ 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.

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

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

◆ 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

Definition at line 94 of file tls_reader.h.

References T.

Referenced by Botan::TLS::Certificate_Verify::Certificate_Verify(), Botan::TLS::Client_Hello::Client_Hello(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::New_Session_Ticket::New_Session_Ticket(), Botan::TLS::Server_Hello::Server_Hello(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and Botan::TLS::SRTP_Protection_Profiles::SRTP_Protection_Profiles().

97  {
98  const size_t num_elems =
99  get_num_elems(len_bytes, sizeof(T), min_elems, max_elems);
100 
101  return get_elem<T, std::vector<T> >(num_elems);
102  }
fe T
Definition: ge.cpp:37

◆ 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.

References T.

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

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  }
fe T
Definition: ge.cpp:37

◆ 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.

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

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:136

◆ 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.

References Botan::make_uint32().

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

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  }
uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition: loadstor.h:65

◆ has_remaining()

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

Definition at line 40 of file tls_reader.h.

References remaining_bytes().

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

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

◆ read_so_far()

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

Definition at line 36 of file tls_reader.h.

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

36 { return m_offset; }

◆ remaining_bytes()

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

Definition at line 38 of file tls_reader.h.

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

38 { return m_buf.size() - m_offset; }

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