Botan 2.13.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 Referencefinal

`#include <tls_extensions.h>`

## Public Member Functions
void | add (Extension *extn)
void | deserialize (TLS_Data_Reader &reader, Connection_Side from)
std::set< Handshake_Extension_Type > | extension_types () const
| Extensions ()=default
| Extensions (TLS_Data_Reader &reader, Connection_Side side)
template<typename T >
T * | get () const
Extension * | get (Handshake_Extension_Type type) const
template<typename T >
bool | has () const
bool | remove_extension (Handshake_Extension_Type typ)
std::vector< uint8_t > | serialize (Connection_Side whoami) const

## Detailed Description

Represents a block of extensions in a hello message

Definition at line 491 of file tls_extensions.h.

## Constructor & Destructor Documentation

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

Botan::TLS::Extensions::Extensions | ( | TLS_Data_Reader & | reader,
|  | Connection_Side | side
| ) |  |
| inline

Definition at line 535 of file tls_extensions.h.

536 {
537 deserialize(reader, side);
538 }
Botan::TLS::Extensions::deserialize
void deserialize(TLS_Data_Reader &reader, Connection_Side from)
Definition: tls_extensions.cpp:72

## Member Function Documentation

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

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

509 {
510 m_extensions[extn->type()].reset(extn);
511 }

void Botan::TLS::Extensions::deserialize | ( | TLS_Data_Reader & | reader,
|  | Connection_Side | from
| ) |  |

Definition at line 72 of file tls_extensions.cpp.

References add(), Botan::TLS::Alert::DECODE_ERROR, Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::TLS::TLS_Data_Reader::has_remaining(), Botan::TLS::TLS_Data_Reader::remaining_bytes(), and type.

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

73 {
74 if(reader.has_remaining())
75 {
76 const uint16_t all_extn_size = reader.get_uint16_t();
77
78 if(reader.remaining_bytes() != all_extn_size)
79 throw Decoding_Error("Bad extension size");
80
81 while(reader.has_remaining())
82 {
83 const uint16_t extension_code = reader.get_uint16_t();
84 const uint16_t extension_size = reader.get_uint16_t();
85
86 const auto type = static_cast<Handshake_Extension_Type>(extension_code);
87
88 if(m_extensions.find(type) != m_extensions.end())
89 throw TLS_Exception(TLS::Alert::DECODE_ERROR,
90 "Peer sent duplicated extensions");
91
92 Extension* extn = make_extension(
93 reader, extension_code, extension_size, from);
94
95 this->add(extn);
96 }
97 }
98 }
Botan::TLS::Extensions::add
void add(Extension *extn)
Definition: tls_extensions.h:508
type
MechanismType type
Definition: p11_mechanism.cpp:44
Botan::TLS::Alert::DECODE_ERROR
Definition: tls_alert.h:44
Botan::PKCS11::Flag::Extension
Botan::TLS::Handshake_Extension_Type
Handshake_Extension_Type
Definition: tls_extensions.h:32

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

Definition at line 143 of file tls_extensions.cpp.

144 {
145 std::set<Handshake_Extension_Type> offers;
146 for(auto i = m_extensions.begin(); i != m_extensions.end(); ++i)
147 offers.insert(i->first);
148 return offers;
149 }
template<typename T >

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

Definition at line 497 of file tls_extensions.h.

References T.

Referenced by Botan::TLS::Client_Hello::Client_Hello(), Botan::TLS::Client_Hello::next_protocols(), Botan::TLS::Client_Hello::prefers_compressed_ec_points(), Botan::TLS::Client_Hello::renegotiation_info(), Botan::TLS::Client_Hello::session_ticket(), Botan::TLS::Client_Hello::signature_schemes(), Botan::TLS::Client_Hello::sni_hostname(), Botan::TLS::Client_Hello::srtp_profiles(), Botan::TLS::Client_Hello::supported_dh_groups(), Botan::TLS::Client_Hello::supported_ecc_curves(), and Botan::TLS::Client_Hello::supported_versions().

498 {
499 return dynamic_cast<T*>(get(T::static_type()));
500 }
T
fe T
Definition: ge.cpp:37

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

Definition at line 513 of file tls_extensions.h.

References type.

514 {
515 auto i = m_extensions.find(type);
516
517 if(i != m_extensions.end())
518 return i->second.get();
519 return nullptr;
520 }
type
MechanismType type
Definition: p11_mechanism.cpp:44
template<typename T >

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

Definition at line 503 of file tls_extensions.h.

Referenced by Botan::TLS::Client_Hello::secure_renegotiation(), Botan::TLS::Client_Hello::sent_signature_algorithms(), Botan::TLS::Client_Hello::supports_alpn(), Botan::TLS::Client_Hello::supports_cert_status_message(), Botan::TLS::Client_Hello::supports_encrypt_then_mac(), Botan::TLS::Client_Hello::supports_extended_master_secret(), and Botan::TLS::Client_Hello::supports_session_ticket().

504 {
505 return get<T>() != nullptr;
506 }

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 134 of file tls_extensions.cpp.

135 {
136 auto i = m_extensions.find(typ);
137 if(i == m_extensions.end())
138 return false;
139 m_extensions.erase(i);
140 return true;
141 }

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

Definition at line 100 of file tls_extensions.cpp.

References Botan::get_byte().

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

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

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