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

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Supported_Groups:
Botan::TLS::Extension

Public Member Functions

std::vector< Group_Paramsdh_groups () const
 
std::vector< Group_Paramsec_groups () const
 
bool empty () const override
 
const std::vector< Group_Params > & groups () const
 
virtual bool is_implemented () const
 
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 
 Supported_Groups (const std::vector< Group_Params > &groups)
 
 Supported_Groups (TLS_Data_Reader &reader, uint16_t extension_size)
 
Extension_Code type () const override
 

Static Public Member Functions

static Extension_Code static_type ()
 

Detailed Description

Supported Groups Extension (RFC 7919)

Definition at line 318 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Supported_Groups() [1/2]

Botan::TLS::Supported_Groups::Supported_Groups ( const std::vector< Group_Params > & groups)
explicit

Definition at line 486 of file tls_extensions.cpp.

486: m_groups(groups) {}
const std::vector< Group_Params > & groups() const

◆ Supported_Groups() [2/2]

Botan::TLS::Supported_Groups::Supported_Groups ( TLS_Data_Reader & reader,
uint16_t extension_size )

Definition at line 530 of file tls_extensions.cpp.

530 {
531 const uint16_t len = reader.get_uint16_t();
532
533 if(len + 2 != extension_size) {
534 throw Decoding_Error("Inconsistent length field in supported groups list");
535 }
536
537 if(len % 2 == 1) {
538 throw Decoding_Error("Supported groups list of strange size");
539 }
540
541 const size_t elems = len / 2;
542
543 for(size_t i = 0; i != elems; ++i) {
544 const auto group = static_cast<Group_Params>(reader.get_uint16_t());
545 // Note: RFC 8446 does not explicitly enforce that groups must be unique.
546 if(!value_exists(m_groups, group)) {
547 m_groups.push_back(group);
548 }
549 }
550}
bool value_exists(const std::vector< T > &vec, const OT &val)
Definition stl_util.h:60

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

Member Function Documentation

◆ dh_groups()

std::vector< Group_Params > Botan::TLS::Supported_Groups::dh_groups ( ) const

Definition at line 502 of file tls_extensions.cpp.

502 {
503 std::vector<Group_Params> dh;
504 for(auto g : m_groups) {
505 if(g.is_in_ffdhe_range()) {
506 dh.push_back(g);
507 }
508 }
509 return dh;
510}

◆ ec_groups()

std::vector< Group_Params > Botan::TLS::Supported_Groups::ec_groups ( ) const

Definition at line 492 of file tls_extensions.cpp.

492 {
493 std::vector<Group_Params> ec;
494 for(auto g : m_groups) {
495 if(g.is_pure_ecc_group()) {
496 ec.push_back(g);
497 }
498 }
499 return ec;
500}

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

◆ empty()

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

Implements Botan::TLS::Extension.

Definition at line 338 of file tls_extensions.h.

338{ return m_groups.empty(); }

◆ groups()

const std::vector< Group_Params > & Botan::TLS::Supported_Groups::groups ( ) const

Definition at line 488 of file tls_extensions.cpp.

488 {
489 return m_groups;
490}

◆ 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::Supported_Groups::serialize ( Connection_Side whoami) const
overridevirtual
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 512 of file tls_extensions.cpp.

512 {
513 std::vector<uint8_t> buf(2);
514
515 for(auto g : m_groups) {
516 const uint16_t id = g.wire_code();
517
518 if(id > 0) {
519 buf.push_back(get_byte<0>(id));
520 buf.push_back(get_byte<1>(id));
521 }
522 }
523
524 buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size() - 2));
525 buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size() - 2));
526
527 return buf;
528}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:75

References Botan::get_byte().

◆ static_type()

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

Definition at line 320 of file tls_extensions.h.

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 322 of file tls_extensions.h.

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

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