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::Extensions Class Reference

`#include <tls_extensions.h>`

## Public Member Functions
void | add (Extension *extn)
void | deserialize (TLS_Data_Reader &reader)
std::set< Handshake_Extension_Type > | extension_types () const
| Extensions ()=default
| Extensions (TLS_Data_Reader &reader)
template<typename T >
T * | get () 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 430 of file tls_extensions.h.

## Constructor & Destructor Documentation

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

Botan::TLS::Extensions::Extensions | ( | TLS_Data_Reader & | reader | ) |
| inline explicit

Definition at line 464 of file tls_extensions.h.

464 { deserialize(reader); }
Botan::TLS::Extensions::deserialize
void deserialize(TLS_Data_Reader &reader)
Definition: tls_extensions.cpp:67

## Member Function Documentation

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

Definition at line 453 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().

454 {
455 m_extensions[extn->type()].reset(extn);
456 }

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 }
Botan::TLS::Extensions::add
void add(Extension *extn)
Definition: tls_extensions.h:453
Botan::PKCS11::Flag::Extension

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 }
template<typename T >

T* Botan::TLS::Extensions::get | ( |  | ) | const
| inline

Definition at line 436 of file tls_extensions.h.

References type.

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

437 {
438 Handshake_Extension_Type type = T::static_type();
439
440 auto i = m_extensions.find(type);
441
442 if(i != m_extensions.end())
443 return dynamic_cast<T*>(i->second.get());
444 return nullptr;
445 }
type
MechanismType type
Definition: p11_mechanism.cpp:43
Botan::TLS::Handshake_Extension_Type
Handshake_Extension_Type
Definition: tls_extensions.h:27
template<typename T >

bool Botan::TLS::Extensions::has | ( |  | ) | const
| inline

Definition at line 448 of file tls_extensions.h.

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

449 {
450 return get<T>() != nullptr;
451 }

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

Definition at line 93 of file tls_extensions.cpp.

References Botan::get_byte().

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 }
Botan::get_byte
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47

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

- src/lib/tls/tls_extensions.h
- src/lib/tls/tls_extensions.cpp