Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::TLS::Extensions Class Referencefinal

#include <tls_extensions.h>

Public Member Functions

void add (Extension *extn)
 
void deserialize (TLS_Data_Reader &reader)
 
std::set< Handshake_Extension_Typeextension_types () const
 
 Extensions ()=default
 
 Extensions (TLS_Data_Reader &reader)
 
template<typename T >
Tget () const
 
template<typename T >
bool has () const
 
std::vector< uint8_t > serialize () const
 

Detailed Description

Represents a block of extensions in a hello message

Definition at line 437 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Extensions() [1/2]

Botan::TLS::Extensions::Extensions ( )
default

◆ Extensions() [2/2]

Botan::TLS::Extensions::Extensions ( TLS_Data_Reader reader)
inlineexplicit

Definition at line 471 of file tls_extensions.h.

471 { deserialize(reader); }
void deserialize(TLS_Data_Reader &reader)

Member Function Documentation

◆ add()

void Botan::TLS::Extensions::add ( Extension extn)
inline

Definition at line 460 of file tls_extensions.h.

References Botan::TLS::Extension::serialize(), and Botan::TLS::Extension::type().

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

461  {
462  m_extensions[extn->type()].reset(extn);
463  }

◆ deserialize()

void Botan::TLS::Extensions::deserialize ( TLS_Data_Reader reader)

Definition at line 67 of file tls_extensions.cpp.

References add(), Botan::TLS::TLS_Data_Reader::discard_next(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::TLS::TLS_Data_Reader::has_remaining(), and Botan::TLS::TLS_Data_Reader::remaining_bytes().

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

68  {
69  if(reader.has_remaining())
70  {
71  const uint16_t all_extn_size = reader.get_uint16_t();
72 
73  if(reader.remaining_bytes() != all_extn_size)
74  throw Decoding_Error("Bad extension size");
75 
76  while(reader.has_remaining())
77  {
78  const uint16_t extension_code = reader.get_uint16_t();
79  const uint16_t extension_size = reader.get_uint16_t();
80 
81  Extension* extn = make_extension(reader,
82  extension_code,
83  extension_size);
84 
85  if(extn)
86  this->add(extn);
87  else // unknown/unhandled extension
88  reader.discard_next(extension_size);
89  }
90  }
91  }
void add(Extension *extn)

◆ extension_types()

std::set< Handshake_Extension_Type > Botan::TLS::Extensions::extension_types ( ) const

Definition at line 127 of file tls_extensions.cpp.

128  {
129  std::set<Handshake_Extension_Type> offers;
130  for(auto i = m_extensions.begin(); i != m_extensions.end(); ++i)
131  offers.insert(i->first);
132  return offers;
133  }

◆ get()

template<typename T >
T* Botan::TLS::Extensions::get ( ) const
inline

◆ has()

template<typename T >
bool Botan::TLS::Extensions::has ( ) const
inline

◆ serialize()

std::vector< uint8_t > Botan::TLS::Extensions::serialize ( ) const

Definition at line 93 of file tls_extensions.cpp.

References Botan::get_byte().

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

94  {
95  std::vector<uint8_t> buf(2); // 2 bytes for length field
96 
97  for(auto& extn : m_extensions)
98  {
99  if(extn.second->empty())
100  continue;
101 
102  const uint16_t extn_code = extn.second->type();
103 
104  std::vector<uint8_t> extn_val = extn.second->serialize();
105 
106  buf.push_back(get_byte(0, extn_code));
107  buf.push_back(get_byte(1, extn_code));
108 
109  buf.push_back(get_byte(0, static_cast<uint16_t>(extn_val.size())));
110  buf.push_back(get_byte(1, static_cast<uint16_t>(extn_val.size())));
111 
112  buf += extn_val;
113  }
114 
115  const uint16_t extn_size = static_cast<uint16_t>(buf.size() - 2);
116 
117  buf[0] = get_byte(0, extn_size);
118  buf[1] = get_byte(1, extn_size);
119 
120  // avoid sending a completely empty extensions block
121  if(buf.size() == 2)
122  return std::vector<uint8_t>();
123 
124  return buf;
125  }
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:39

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