Botan 3.13.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 (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 247 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Supported_Groups() [1/2]

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

Definition at line 621 of file tls_extensions.cpp.

621: m_groups(std::move(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 667 of file tls_extensions.cpp.

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

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

637 {
638 std::vector<Group_Params> dh;
639 for(auto g : m_groups) {
640 if(g.is_in_ffdhe_range()) {
641 dh.push_back(g);
642 }
643 }
644 return dh;
645}

◆ ec_groups()

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

Definition at line 627 of file tls_extensions.cpp.

627 {
628 std::vector<Group_Params> ec;
629 for(auto g : m_groups) {
630 if(g.is_pure_ecc_group()) {
631 ec.push_back(g);
632 }
633 }
634 return ec;
635}

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

◆ empty()

bool Botan::TLS::Supported_Groups::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 267 of file tls_extensions.h.

267{ return m_groups.empty(); }

◆ groups()

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

Definition at line 623 of file tls_extensions.cpp.

623 {
624 return m_groups;
625}

Referenced by Supported_Groups().

◆ 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::Supported_Groups::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 647 of file tls_extensions.cpp.

647 {
648 std::vector<uint8_t> buf(2);
649
650 for(auto g : m_groups) {
651 const uint16_t id = g.wire_code();
652
653 if(id > 0) {
654 buf.push_back(get_byte<0>(id));
655 buf.push_back(get_byte<1>(id));
656 }
657 }
658
659 // RFC 8446 4.2.7: NamedGroup named_group_list<2..2^16-1>;
660 BOTAN_ASSERT_NOMSG(buf.size() - 2 <= 0xFFFF);
661 buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size() - 2));
662 buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size() - 2));
663
664 return buf;
665}
#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 249 of file tls_extensions.h.

References Botan::TLS::SupportedGroups.

Referenced by type().

◆ type()

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

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 251 of file tls_extensions.h.

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

References static_type().


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