Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::TLS::TLS_Data_Reader Class Reference

`#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< 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)
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

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) {}
type
MechanismType type
Definition: p11_mechanism.cpp:43

## Member Function Documentation

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 }
Botan::TLS::TLS_Data_Reader::has_remaining
bool has_remaining() const
Definition: tls_reader.h:40

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

Definition at line 47 of file tls_reader.h.

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

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

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

Definition at line 70 of file tls_reader.h.

Referenced by Botan::TLS::Certificate_Status_Request::Certificate_Status_Request(), Botan::TLS::Certificate_Verify::Certificate_Verify(), Botan::TLS::Client_Hello::Client_Hello(), Botan::TLS::Server_Hello::Server_Hello(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), Botan::TLS::Server_Name_Indicator::Server_Name_Indicator(), Botan::TLS::Signature_Algorithms::Signature_Algorithms(), and Botan::TLS::Supported_Point_Formats::Supported_Point_Formats().

71 {
72 assert_at_least(1);
73 uint8_t result = m_buf[m_offset];
74 m_offset += 1;
75 return result;
76 }
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 }
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 }
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.

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

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 }

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 }

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.

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(reinterpret_cast<char*>(v.data()), v.size());
123 }

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

Definition at line 62 of file tls_reader.h.

References Botan::make_uint16().

Referenced by Botan::TLS::Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification(), Botan::TLS::Certificate_Req::Certificate_Req(), Botan::TLS::Extensions::deserialize(), Botan::TLS::Server_Hello::Server_Hello(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), Botan::TLS::Server_Name_Indicator::Server_Name_Indicator(), Botan::TLS::Signature_Algorithms::Signature_Algorithms(), and Botan::TLS::Supported_Elliptic_Curves::Supported_Elliptic_Curves().

63 {
64 assert_at_least(2);
65 uint16_t result = make_uint16(m_buf[m_offset], m_buf[m_offset+1]);
66 m_offset += 2;
67 return result;
68 }
Botan::make_uint16
uint16_t make_uint16(uint8_t i0, uint8_t i1)
Definition: loadstor.h:60

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

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); }
Botan::TLS::TLS_Data_Reader::remaining_bytes
size_t remaining_bytes() const
Definition: tls_reader.h:38

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; }

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:

- src/lib/tls/tls_reader.h