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

#include <tls_extensions.h>

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

Public Member Functions

 Cookie (const 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 593 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Cookie() [1/2]

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

Definition at line 828 of file tls_extensions.cpp.

828: m_cookie(cookie) {}

◆ Cookie() [2/2]

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

Definition at line 830 of file tls_extensions.cpp.

830 {
831 if(extension_size == 0) {
832 return;
833 }
834
835 const uint16_t len = reader.get_uint16_t();
836
837 if(len == 0) {
838 // Based on RFC 8446 4.2.2, len of the Cookie buffer must be at least 1
839 throw Decoding_Error("Cookie length must be at least 1 byte");
840 }
841
842 if(len > reader.remaining_bytes()) {
843 throw Decoding_Error("Not enough bytes in the buffer to decode Cookie");
844 }
845
846 for(size_t i = 0; i < len; ++i) {
847 m_cookie.push_back(reader.get_byte());
848 }
849}

References Botan::TLS::TLS_Data_Reader::get_byte(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), and Botan::TLS::TLS_Data_Reader::remaining_bytes().

Member Function Documentation

◆ empty()

bool Botan::TLS::Cookie::empty ( ) const
inlineoverridevirtual
Returns
if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 601 of file tls_extensions.h.

601{ return m_cookie.empty(); }

◆ get_cookie()

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

Definition at line 603 of file tls_extensions.h.

603{ return m_cookie; }

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

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited
Returns
true if this extension is known and implemented by Botan

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 116 of file tls_extensions.h.

116{ return true; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::Cookie::serialize ( Connection_Side whoami) const
overridevirtual
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 851 of file tls_extensions.cpp.

851 {
852 std::vector<uint8_t> buf;
853
854 const uint16_t len = static_cast<uint16_t>(m_cookie.size());
855
856 buf.push_back(get_byte<0>(len));
857 buf.push_back(get_byte<1>(len));
858
859 for(const auto& cookie_byte : m_cookie) {
860 buf.push_back(cookie_byte);
861 }
862
863 return buf;
864}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:75

References Botan::get_byte().

◆ static_type()

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

◆ type()

Extension_Code Botan::TLS::Cookie::type ( ) const
inlineoverridevirtual
Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 597 of file tls_extensions.h.

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

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