Botan  2.15.0
Crypto and TLS for C++11
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
 
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 
 Supported_Versions (Protocol_Version version, const Policy &policy)
 
 Supported_Versions (Protocol_Version version)
 
 Supported_Versions (TLS_Data_Reader &reader, uint16_t extension_size, Connection_Side from)
 
bool supports (Protocol_Version version) const
 
Handshake_Extension_Type type () const override
 
const std::vector< Protocol_Versionversions () const
 

Static Public Member Functions

static Handshake_Extension_Type static_type ()
 

Detailed Description

Supported Versions from RFC 8446

Definition at line 435 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 604 of file tls_extensions.cpp.

References Botan::TLS::Policy::allow_dtls10(), Botan::TLS::Policy::allow_dtls12(), Botan::TLS::Policy::allow_tls10(), Botan::TLS::Policy::allow_tls11(), Botan::TLS::Policy::allow_tls12(), Botan::TLS::Protocol_Version::DTLS_V10, Botan::TLS::Protocol_Version::DTLS_V12, Botan::TLS::Protocol_Version::is_datagram_protocol(), Botan::TLS::Protocol_Version::TLS_V10, Botan::TLS::Protocol_Version::TLS_V11, and Botan::TLS::Protocol_Version::TLS_V12.

605  {
606  if(offer.is_datagram_protocol())
607  {
608  if(offer >= Protocol_Version::DTLS_V12 && policy.allow_dtls12())
609  m_versions.push_back(Protocol_Version::DTLS_V12);
610 #if defined(BOTAN_HAS_TLS_V10)
611  if(offer >= Protocol_Version::DTLS_V10 && policy.allow_dtls10())
612  m_versions.push_back(Protocol_Version::DTLS_V10);
613 #endif
614  }
615  else
616  {
617  if(offer >= Protocol_Version::TLS_V12 && policy.allow_tls12())
618  m_versions.push_back(Protocol_Version::TLS_V12);
619 #if defined(BOTAN_HAS_TLS_V10)
620  if(offer >= Protocol_Version::TLS_V11 && policy.allow_tls11())
621  m_versions.push_back(Protocol_Version::TLS_V11);
622  if(offer >= Protocol_Version::TLS_V10 && policy.allow_tls10())
623  m_versions.push_back(Protocol_Version::TLS_V10);
624 #endif
625  }
626  }

◆ Supported_Versions() [2/3]

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

Definition at line 449 of file tls_extensions.h.

450  {
451  m_versions.push_back(version);
452  }

◆ Supported_Versions() [3/3]

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

Definition at line 628 of file tls_extensions.cpp.

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

631  {
632  if(from == Connection_Side::SERVER)
633  {
634  if(extension_size != 2)
635  throw Decoding_Error("Server sent invalid supported_versions extension");
636  m_versions.push_back(Protocol_Version(reader.get_uint16_t()));
637  }
638  else
639  {
640  auto versions = reader.get_range<uint16_t>(1, 1, 127);
641 
642  for(auto v : versions)
643  m_versions.push_back(Protocol_Version(v));
644 
645  if(extension_size != 1+2*versions.size())
646  throw Decoding_Error("Client sent invalid supported_versions extension");
647  }
648  }
const std::vector< Protocol_Version > versions() const

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

445 { return m_versions.empty(); }

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

References BOTAN_ASSERT_NOMSG, Botan::get_byte(), and Botan::TLS::SERVER.

578  {
579  std::vector<uint8_t> buf;
580 
581  if(whoami == Connection_Side::SERVER)
582  {
583  BOTAN_ASSERT_NOMSG(m_versions.size() == 1);
584  buf.push_back(m_versions[0].major_version());
585  buf.push_back(m_versions[0].minor_version());
586  }
587  else
588  {
589  BOTAN_ASSERT_NOMSG(m_versions.size() >= 1);
590  const uint8_t len = static_cast<uint8_t>(m_versions.size() * 2);
591 
592  buf.push_back(len);
593 
594  for(Protocol_Version version : m_versions)
595  {
596  buf.push_back(get_byte(0, version.major_version()));
597  buf.push_back(get_byte(1, version.minor_version()));
598  }
599  }
600 
601  return buf;
602  }
constexpr uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:41
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:68

◆ static_type()

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

◆ supports()

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

Definition at line 650 of file tls_extensions.cpp.

651  {
652  for(auto v : m_versions)
653  if(version == v)
654  return true;
655  return false;
656  }

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 441 of file tls_extensions.h.

441 { return static_type(); }
static Handshake_Extension_Type static_type()

◆ versions()

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

Definition at line 460 of file tls_extensions.h.

Referenced by Supported_Versions().

460 { return m_versions; }

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