Botan 3.12.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 234 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 616 of file tls_extensions.cpp.

616: 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 662 of file tls_extensions.cpp.

662 {
663 const uint16_t len = reader.get_uint16_t();
664
665 if(len + 2 != extension_size) {
666 throw Decoding_Error("Inconsistent length field in supported groups list");
667 }
668
669 // RFC 8446 4.2.7: NamedGroup named_group_list<2..2^16-1>;
670 if(len == 0) {
671 throw Decoding_Error("Empty supported groups list");
672 }
673
674 if(len % 2 == 1) {
675 throw Decoding_Error("Supported groups list of strange size");
676 }
677
678 const size_t elems = len / 2;
679
680 std::unordered_set<uint16_t> seen;
681 for(size_t i = 0; i != elems; ++i) {
682 const auto group = static_cast<Group_Params>(reader.get_uint16_t());
683 // Note: RFC 8446 does not explicitly enforce that groups must be unique.
684 if(seen.insert(group.wire_code()).second) {
685 m_groups.push_back(group);
686 }
687 }
688}

References Botan::TLS::TLS_Data_Reader::get_uint16_t().

Member Function Documentation

◆ dh_groups()

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

Definition at line 632 of file tls_extensions.cpp.

632 {
633 std::vector<Group_Params> dh;
634 for(auto g : m_groups) {
635 if(g.is_in_ffdhe_range()) {
636 dh.push_back(g);
637 }
638 }
639 return dh;
640}

◆ ec_groups()

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

Definition at line 622 of file tls_extensions.cpp.

622 {
623 std::vector<Group_Params> ec;
624 for(auto g : m_groups) {
625 if(g.is_pure_ecc_group()) {
626 ec.push_back(g);
627 }
628 }
629 return ec;
630}

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

254{ return m_groups.empty(); }

◆ groups()

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

Definition at line 618 of file tls_extensions.cpp.

618 {
619 return m_groups;
620}

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

100{ 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 642 of file tls_extensions.cpp.

642 {
643 std::vector<uint8_t> buf(2);
644
645 for(auto g : m_groups) {
646 const uint16_t id = g.wire_code();
647
648 if(id > 0) {
649 buf.push_back(get_byte<0>(id));
650 buf.push_back(get_byte<1>(id));
651 }
652 }
653
654 // RFC 8446 4.2.7: NamedGroup named_group_list<2..2^16-1>;
655 BOTAN_ASSERT_NOMSG(buf.size() - 2 <= 0xFFFF);
656 buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size() - 2));
657 buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size() - 2));
658
659 return buf;
660}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References BOTAN_ASSERT_NOMSG, and Botan::get_byte().

◆ static_type()

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

Definition at line 236 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 238 of file tls_extensions.h.

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

References static_type().


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