Botan  2.7.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
 
Extensionget (Handshake_Extension_Type type) const
 
template<typename T >
bool has () const
 
bool remove_extension (Handshake_Extension_Type typ)
 
std::vector< uint8_t > serialize () const
 

Detailed Description

Represents a block of extensions in a hello message

Definition at line 441 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 485 of file tls_extensions.h.

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

Member Function Documentation

◆ add()

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

Definition at line 458 of file tls_extensions.h.

References Botan::TLS::Extension::type().

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

459  {
460  m_extensions[extn->type()].reset(extn);
461  }

◆ deserialize()

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

Definition at line 68 of file tls_extensions.cpp.

References add(), 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().

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

◆ extension_types()

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

Definition at line 134 of file tls_extensions.cpp.

135  {
136  std::set<Handshake_Extension_Type> offers;
137  for(auto i = m_extensions.begin(); i != m_extensions.end(); ++i)
138  offers.insert(i->first);
139  return offers;
140  }

◆ get() [1/2]

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

◆ get() [2/2]

Extension* Botan::TLS::Extensions::get ( Handshake_Extension_Type  type) const
inline

Definition at line 463 of file tls_extensions.h.

References type.

464  {
465  auto i = m_extensions.find(type);
466 
467  if(i != m_extensions.end())
468  return i->second.get();
469  return nullptr;
470  }
MechanismType type

◆ has()

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

◆ remove_extension()

bool Botan::TLS::Extensions::remove_extension ( Handshake_Extension_Type  typ)

Remvoe an extension from this extensions object, if it exists. Returns true if the extension existed (and thus is now removed), otherwise false (the extension wasn't set in the first place).

Definition at line 125 of file tls_extensions.cpp.

126  {
127  auto i = m_extensions.find(typ);
128  if(i == m_extensions.end())
129  return false;
130  m_extensions.erase(i);
131  return true;
132  }

◆ serialize()

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

Definition at line 91 of file tls_extensions.cpp.

References Botan::get_byte().

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