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

#include <tls_extensions_13.h>

Inheritance diagram for Botan::TLS::Cookie:
Botan::TLS::Extension

Public Member Functions

 Cookie (std::vector< uint8_t > cookie)
 Cookie (TLS_Data_Reader &reader, uint16_t extension_size)
bool empty () const override
const std::vector< uint8_t > & get_cookie () const
virtual bool is_implemented () const
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

Cookie from RFC 8446 4.2.2

Definition at line 42 of file tls_extensions_13.h.

Constructor & Destructor Documentation

◆ Cookie() [1/2]

Botan::TLS::Cookie::Cookie ( std::vector< uint8_t > cookie)
explicit

Definition at line 24 of file tls_extensions_13.cpp.

24: m_cookie(std::move(cookie)) {}

◆ Cookie() [2/2]

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

Definition at line 26 of file tls_extensions_13.cpp.

26 {
27 // RFC 8446 4.2.2
28 // struct {
29 // opaque cookie<1..2^16-1>;
30 // } Cookie;
31 //
32 // The wire form requires a 2-byte length field plus at least one byte of
33 // cookie data, so the minimum extension size is 3 bytes.
34 if(extension_size < 3) {
35 throw Decoding_Error("Empty cookie extension is illegal");
36 }
37
38 const uint16_t len = reader.get_uint16_t();
39
40 if(static_cast<size_t>(len) + 2 != extension_size) {
41 throw Decoding_Error("Inconsistent length in cookie extension");
42 }
43
44 m_cookie = reader.get_fixed<uint8_t>(len);
45}

References Botan::TLS::TLS_Data_Reader::get_fixed(), and Botan::TLS::TLS_Data_Reader::get_uint16_t().

Member Function Documentation

◆ empty()

bool Botan::TLS::Cookie::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 50 of file tls_extensions_13.h.

50{ return m_cookie.empty(); }

◆ get_cookie()

const std::vector< uint8_t > & Botan::TLS::Cookie::get_cookie ( ) const
inline

Definition at line 52 of file tls_extensions_13.h.

52{ return m_cookie; }

Referenced by Botan::TLS::Client_Hello_13::retry().

◆ 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; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::Cookie::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 47 of file tls_extensions_13.cpp.

47 {
48 std::vector<uint8_t> buf;
49 append_tls_length_value(buf, m_cookie, 2);
50 return buf;
51}
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Definition tls_reader.h:177

References Botan::TLS::append_tls_length_value().

◆ static_type()

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

◆ type()

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

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 46 of file tls_extensions_13.h.

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

References static_type().


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