Botan 3.3.0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::TLS::Supported_Versions Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Supported_Versions:
Botan::TLS::Extension

Public Member Functions

bool empty () const override
 
virtual bool is_implemented () const
 
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 
 Supported_Versions (Protocol_Version version)
 
 Supported_Versions (Protocol_Version version, const Policy &policy)
 
 Supported_Versions (TLS_Data_Reader &reader, uint16_t extension_size, Connection_Side from)
 
bool supports (Protocol_Version version) const
 
Extension_Code type () const override
 
const std::vector< Protocol_Version > & versions () const
 

Static Public Member Functions

static Extension_Code static_type ()
 

Detailed Description

Supported Versions from RFC 8446

Definition at line 536 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Supported_Versions() [1/3]

Botan::TLS::Supported_Versions::Supported_Versions ( Protocol_Version version,
const Policy & policy )

Definition at line 729 of file tls_extensions.cpp.

729 {
730 if(offer.is_datagram_protocol()) {
731#if defined(BOTAN_HAS_TLS_12)
732 if(offer >= Protocol_Version::DTLS_V12 && policy.allow_dtls12()) {
733 m_versions.push_back(Protocol_Version::DTLS_V12);
734 }
735#endif
736 } else {
737#if defined(BOTAN_HAS_TLS_13)
738 if(offer >= Protocol_Version::TLS_V13 && policy.allow_tls13()) {
739 m_versions.push_back(Protocol_Version::TLS_V13);
740 }
741#endif
742#if defined(BOTAN_HAS_TLS_12)
743 if(offer >= Protocol_Version::TLS_V12 && policy.allow_tls12()) {
744 m_versions.push_back(Protocol_Version::TLS_V12);
745 }
746#endif
747 }
748}

References Botan::TLS::Policy::allow_dtls12(), Botan::TLS::Policy::allow_tls12(), Botan::TLS::Policy::allow_tls13(), and Botan::TLS::Protocol_Version::is_datagram_protocol().

◆ Supported_Versions() [2/3]

Botan::TLS::Supported_Versions::Supported_Versions ( Protocol_Version version)
inline

Definition at line 548 of file tls_extensions.h.

548{ m_versions.push_back(version); }

◆ Supported_Versions() [3/3]

Botan::TLS::Supported_Versions::Supported_Versions ( TLS_Data_Reader & reader,
uint16_t extension_size,
Connection_Side from )

Definition at line 750 of file tls_extensions.cpp.

750 {
751 if(from == Connection_Side::Server) {
752 if(extension_size != 2) {
753 throw Decoding_Error("Server sent invalid supported_versions extension");
754 }
755 m_versions.push_back(Protocol_Version(reader.get_uint16_t()));
756 } else {
757 auto versions = reader.get_range<uint16_t>(1, 1, 127);
758
759 for(auto v : versions) {
760 m_versions.push_back(Protocol_Version(v));
761 }
762
763 if(extension_size != 1 + 2 * versions.size()) {
764 throw Decoding_Error("Client sent invalid supported_versions extension");
765 }
766 }
767}
const std::vector< Protocol_Version > & versions() const

References Botan::TLS::TLS_Data_Reader::get_range(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::TLS::Server, and versions().

Member Function Documentation

◆ empty()

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

Implements Botan::TLS::Extension.

Definition at line 544 of file tls_extensions.h.

544{ return m_versions.empty(); }

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

Implements Botan::TLS::Extension.

Definition at line 707 of file tls_extensions.cpp.

707 {
708 std::vector<uint8_t> buf;
709
710 if(whoami == Connection_Side::Server) {
711 BOTAN_ASSERT_NOMSG(m_versions.size() == 1);
712 buf.push_back(m_versions[0].major_version());
713 buf.push_back(m_versions[0].minor_version());
714 } else {
715 BOTAN_ASSERT_NOMSG(!m_versions.empty());
716 const uint8_t len = static_cast<uint8_t>(m_versions.size() * 2);
717
718 buf.push_back(len);
719
720 for(Protocol_Version version : m_versions) {
721 buf.push_back(version.major_version());
722 buf.push_back(version.minor_version());
723 }
724 }
725
726 return buf;
727}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59

References BOTAN_ASSERT_NOMSG, and Botan::TLS::Server.

◆ static_type()

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

Definition at line 538 of file tls_extensions.h.

◆ supports()

bool Botan::TLS::Supported_Versions::supports ( Protocol_Version version) const

Definition at line 769 of file tls_extensions.cpp.

769 {
770 for(auto v : m_versions) {
771 if(version == v) {
772 return true;
773 }
774 }
775 return false;
776}

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 540 of file tls_extensions.h.

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

◆ versions()

const std::vector< Protocol_Version > & Botan::TLS::Supported_Versions::versions ( ) const
inline

Definition at line 554 of file tls_extensions.h.

554{ return m_versions; }

Referenced by Supported_Versions().


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