Botan  2.11.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 602 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.

603  {
604  if(offer.is_datagram_protocol())
605  {
606  if(offer >= Protocol_Version::DTLS_V12 && policy.allow_dtls12())
607  m_versions.push_back(Protocol_Version::DTLS_V12);
608  if(offer >= Protocol_Version::DTLS_V10 && policy.allow_dtls10())
609  m_versions.push_back(Protocol_Version::DTLS_V10);
610  }
611  else
612  {
613  if(offer >= Protocol_Version::TLS_V12 && policy.allow_tls12())
614  m_versions.push_back(Protocol_Version::TLS_V12);
615  if(offer >= Protocol_Version::TLS_V11 && policy.allow_tls11())
616  m_versions.push_back(Protocol_Version::TLS_V11);
617  if(offer >= Protocol_Version::TLS_V10 && policy.allow_tls10())
618  m_versions.push_back(Protocol_Version::TLS_V10);
619  }
620  }

◆ 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 622 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().

625  {
626  if(from == Connection_Side::SERVER)
627  {
628  if(extension_size != 2)
629  throw Decoding_Error("Server sent invalid supported_versions extension");
630  m_versions.push_back(Protocol_Version(reader.get_uint16_t()));
631  }
632  else
633  {
634  auto versions = reader.get_range<uint16_t>(1, 1, 127);
635 
636  for(auto v : versions)
637  m_versions.push_back(Protocol_Version(v));
638 
639  if(extension_size != 1+2*versions.size())
640  throw Decoding_Error("Client sent invalid supported_versions extension");
641  }
642  }
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 575 of file tls_extensions.cpp.

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

576  {
577  std::vector<uint8_t> buf;
578 
579  if(whoami == Connection_Side::SERVER)
580  {
581  BOTAN_ASSERT_NOMSG(m_versions.size() == 1);
582  buf.push_back(m_versions[0].major_version());
583  buf.push_back(m_versions[0].minor_version());
584  }
585  else
586  {
587  BOTAN_ASSERT_NOMSG(m_versions.size() >= 1);
588  const uint8_t len = static_cast<uint8_t>(m_versions.size() * 2);
589 
590  buf.push_back(len);
591 
592  for(Protocol_Version version : m_versions)
593  {
594  buf.push_back(get_byte(0, version.major_version()));
595  buf.push_back(get_byte(1, version.minor_version()));
596  }
597  }
598 
599  return buf;
600  }
constexpr uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:39
#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 644 of file tls_extensions.cpp.

645  {
646  for(auto v : m_versions)
647  if(version == v)
648  return true;
649  return false;
650  }

◆ 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: