Botan 3.13.0
Crypto and TLS for C&
Botan::TLS::PSK_Key_Exchange_Modes Class Referencefinal

#include <tls_extensions_13.h>

Inheritance diagram for Botan::TLS::PSK_Key_Exchange_Modes:
Botan::TLS::Extension

Public Member Functions

bool empty () const override
virtual bool is_implemented () const
const std::vector< PSK_Key_Exchange_Mode > & modes () const
 PSK_Key_Exchange_Modes (std::vector< PSK_Key_Exchange_Mode > modes)
 PSK_Key_Exchange_Modes (TLS_Data_Reader &reader, uint16_t extension_size)
std::vector< uint8_t > serialize (Connection_Side whoami) const override
Extension_Code type () const override

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Pre-Shared Key Exchange Modes from RFC 8446 4.2.9

Definition at line 65 of file tls_extensions_13.h.

Constructor & Destructor Documentation

◆ PSK_Key_Exchange_Modes() [1/2]

Botan::TLS::PSK_Key_Exchange_Modes::PSK_Key_Exchange_Modes ( std::vector< PSK_Key_Exchange_Mode > modes)
inlineexplicit

Definition at line 77 of file tls_extensions_13.h.

77: m_modes(std::move(modes)) {}
const std::vector< PSK_Key_Exchange_Mode > & modes() const

References modes().

◆ PSK_Key_Exchange_Modes() [2/2]

Botan::TLS::PSK_Key_Exchange_Modes::PSK_Key_Exchange_Modes ( TLS_Data_Reader & reader,
uint16_t extension_size )
explicit

Definition at line 65 of file tls_extensions_13.cpp.

65 {
66 // RFC 8446 4.2.9
67 // struct {
68 // PskKeyExchangeMode ke_modes<1..255>;
69 // } PskKeyExchangeModes;
70 //
71 // The wire form is a 1-byte length followed by mode_count mode bytes,
72 // with mode_count in [1, 255], so the extension size is in [2, 256].
73 if(extension_size < 2) {
74 throw Decoding_Error("Empty psk_key_exchange_modes extension is illegal");
75 }
76
77 const auto mode_count = reader.get_byte();
78 if(static_cast<size_t>(mode_count) + 1 != extension_size) {
79 throw Decoding_Error("Inconsistent length in psk_key_exchange_modes extension");
80 }
81
82 for(uint16_t i = 0; i < mode_count; ++i) {
83 const auto mode = static_cast<PSK_Key_Exchange_Mode>(reader.get_byte());
85 m_modes.push_back(mode);
86 }
87 }
88}

References Botan::TLS::TLS_Data_Reader::get_byte(), Botan::TLS::PSK_DHE_KE, and Botan::TLS::PSK_KE.

Member Function Documentation

◆ empty()

bool Botan::TLS::PSK_Key_Exchange_Modes::empty ( ) const
inlineoverridevirtual

Predicate if a TLS extension should be included or not

Returns
true if this extension should be encoded, otherwise false

Implements Botan::TLS::Extension.

Definition at line 73 of file tls_extensions_13.h.

73{ return m_modes.empty(); }

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited

Predicate if the extension is known/implemented

Note
this exists primarily to support unknown extension handling and doesn't need to be overridden even in the custom extension case.
Returns
true if this extension is known

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 113 of file tls_extensions.h.

113{ return true; }

◆ modes()

const std::vector< PSK_Key_Exchange_Mode > & Botan::TLS::PSK_Key_Exchange_Modes::modes ( ) const
inline

Definition at line 75 of file tls_extensions_13.h.

75{ return m_modes; }

Referenced by PSK_Key_Exchange_Modes().

◆ serialize()

std::vector< uint8_t > Botan::TLS::PSK_Key_Exchange_Modes::serialize ( Connection_Side whoami) const
overridevirtual

Serialize a TLS extension

Parameters
whoamiwhich peer we are acting as in the protocol
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 53 of file tls_extensions_13.cpp.

53 {
54 std::vector<uint8_t> buf;
55
56 BOTAN_ASSERT_NOMSG(m_modes.size() < 256);
57 buf.push_back(static_cast<uint8_t>(m_modes.size()));
58 for(const auto& mode : m_modes) {
59 buf.push_back(static_cast<uint8_t>(mode));
60 }
61
62 return buf;
63}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References BOTAN_ASSERT_NOMSG.

◆ static_type()

Extension_Code Botan::TLS::PSK_Key_Exchange_Modes::static_type ( )
inlinestatic

Definition at line 67 of file tls_extensions_13.h.

References Botan::TLS::PskKeyExchangeModes.

Referenced by type().

◆ type()

Extension_Code Botan::TLS::PSK_Key_Exchange_Modes::type ( ) const
inlineoverridevirtual

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 69 of file tls_extensions_13.h.

69{ return static_type(); }
static Extension_Code static_type()

References static_type().


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