Botan 3.9.0
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 317 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 497 of file tls_extensions.cpp.

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

References groups().

◆ Supported_Groups() [2/2]

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

Definition at line 541 of file tls_extensions.cpp.

541 {
542 const uint16_t len = reader.get_uint16_t();
543
544 if(len + 2 != extension_size) {
545 throw Decoding_Error("Inconsistent length field in supported groups list");
546 }
547
548 if(len % 2 == 1) {
549 throw Decoding_Error("Supported groups list of strange size");
550 }
551
552 const size_t elems = len / 2;
553
554 for(size_t i = 0; i != elems; ++i) {
555 const auto group = static_cast<Group_Params>(reader.get_uint16_t());
556 // Note: RFC 8446 does not explicitly enforce that groups must be unique.
557 if(!value_exists(m_groups, group)) {
558 m_groups.push_back(group);
559 }
560 }
561}
bool value_exists(const std::vector< T > &vec, const OT &val)
Definition stl_util.h:52

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

513 {
514 std::vector<Group_Params> dh;
515 for(auto g : m_groups) {
516 if(g.is_in_ffdhe_range()) {
517 dh.push_back(g);
518 }
519 }
520 return dh;
521}

◆ ec_groups()

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

Definition at line 503 of file tls_extensions.cpp.

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

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 337 of file tls_extensions.h.

337{ return m_groups.empty(); }

◆ groups()

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

Definition at line 499 of file tls_extensions.cpp.

499 {
500 return m_groups;
501}

Referenced by Supported_Groups().

◆ 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 115 of file tls_extensions.h.

115{ 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 523 of file tls_extensions.cpp.

523 {
524 std::vector<uint8_t> buf(2);
525
526 for(auto g : m_groups) {
527 const uint16_t id = g.wire_code();
528
529 if(id > 0) {
530 buf.push_back(get_byte<0>(id));
531 buf.push_back(get_byte<1>(id));
532 }
533 }
534
535 buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size() - 2));
536 buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size() - 2));
537
538 return buf;
539}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References Botan::get_byte().

◆ static_type()

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

Definition at line 319 of file tls_extensions.h.

References Botan::TLS::SupportedGroups.

Referenced by type().

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 321 of file tls_extensions.h.

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

References static_type().


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