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

#include <tls_version.h>

Public Member Functions

bool is_datagram_protocol () const
 
bool is_pre_tls_13 () const
 
bool is_tls_13_or_later () const
 
bool known_version () const
 
uint8_t major_version () const
 
uint8_t minor_version () const
 
bool operator!= (const Protocol_Version &other) const
 
bool operator< (const Protocol_Version &other) const
 
bool operator<= (const Protocol_Version &other) const
 
bool operator== (const Protocol_Version &other) const
 
bool operator> (const Protocol_Version &other) const
 
bool operator>= (const Protocol_Version &other) const
 
 Protocol_Version ()
 
 Protocol_Version (uint16_t code)
 
 Protocol_Version (uint8_t major, uint8_t minor)
 
 Protocol_Version (Version_Code named_version)
 
std::string to_string () const
 
bool valid () const
 
uint16_t version_code () const
 

Static Public Member Functions

static Protocol_Version latest_dtls_version ()
 
static Protocol_Version latest_tls_version ()
 

Detailed Description

TLS Protocol Version

Definition at line 29 of file tls_version.h.

Constructor & Destructor Documentation

◆ Protocol_Version() [1/4]

Botan::TLS::Protocol_Version::Protocol_Version ( )
inline

Definition at line 49 of file tls_version.h.

49: m_version(0) {}

◆ Protocol_Version() [2/4]

Botan::TLS::Protocol_Version::Protocol_Version ( uint16_t code)
inlineexplicit

Definition at line 51 of file tls_version.h.

51: m_version(code) {}

◆ Protocol_Version() [3/4]

Botan::TLS::Protocol_Version::Protocol_Version ( Version_Code named_version)
inline
Parameters
named_versiona specific named version of the protocol

Definition at line 56 of file tls_version.h.

56: Protocol_Version(static_cast<uint16_t>(named_version)) {}

◆ Protocol_Version() [4/4]

Botan::TLS::Protocol_Version::Protocol_Version ( uint8_t major,
uint8_t minor )
inline
Parameters
majorthe major version
minorthe minor version

Definition at line 62 of file tls_version.h.

62 :
63 Protocol_Version(static_cast<uint16_t>((static_cast<uint16_t>(major) << 8) | minor)) {}

Member Function Documentation

◆ is_datagram_protocol()

bool Botan::TLS::Protocol_Version::is_datagram_protocol ( ) const

◆ is_pre_tls_13()

bool Botan::TLS::Protocol_Version::is_pre_tls_13 ( ) const

◆ is_tls_13_or_later()

bool Botan::TLS::Protocol_Version::is_tls_13_or_later ( ) const
Returns
true if this version indicates a (D)TLS newer than 1.3

Definition at line 45 of file tls_version.cpp.

45 {
46 return (!is_datagram_protocol() && *this >= Protocol_Version::TLS_V13) ||
47 (is_datagram_protocol() && *this >= Protocol_Version::DTLS_V13);
48}

References is_datagram_protocol().

◆ known_version()

bool Botan::TLS::Protocol_Version::known_version ( ) const
Returns
true if this is a protocol version we know about

Definition at line 84 of file tls_version.cpp.

84 {
85 return (m_version == static_cast<uint16_t>(Protocol_Version::TLS_V12) ||
86#if defined(BOTAN_HAS_TLS_13)
87 m_version == static_cast<uint16_t>(Protocol_Version::TLS_V13) ||
88#endif
89 m_version == static_cast<uint16_t>(Protocol_Version::DTLS_V12));
90}
#define BOTAN_HAS_TLS_13
Definition build.h:350

References BOTAN_HAS_TLS_13.

◆ latest_dtls_version()

static Protocol_Version Botan::TLS::Protocol_Version::latest_dtls_version ( )
inlinestatic
Returns
latest known DTLS version

Definition at line 47 of file tls_version.h.

References Botan::TLS::DTLS_V12.

◆ latest_tls_version()

static Protocol_Version Botan::TLS::Protocol_Version::latest_tls_version ( )
inlinestatic
Returns
latest known TLS version

Definition at line 36 of file tls_version.h.

36 {
37#if defined(BOTAN_HAS_TLS_13)
39#else
41#endif
42 }

References Botan::TLS::TLS_V12, and Botan::TLS::TLS_V13.

◆ major_version()

uint8_t Botan::TLS::Protocol_Version::major_version ( ) const
inline

◆ minor_version()

uint8_t Botan::TLS::Protocol_Version::minor_version ( ) const
inline
Returns
minor version of the protocol version

Definition at line 83 of file tls_version.h.

83{ return static_cast<uint8_t>(m_version & 0xFF); }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Session::DER_encode(), Botan::TLS::Connection_Cipher_State::format_ad(), Botan::TLS::Hello_Verify_Request::serialize(), to_string(), and valid().

◆ operator!=()

bool Botan::TLS::Protocol_Version::operator!= ( const Protocol_Version & other) const
inline
Returns
if this version is not equal to other

Definition at line 118 of file tls_version.h.

118{ return (m_version != other.m_version); }

◆ operator<()

bool Botan::TLS::Protocol_Version::operator< ( const Protocol_Version & other) const
inline
Returns
if this version is earlier to other

Definition at line 133 of file tls_version.h.

133{ return !(*this >= other); }

◆ operator<=()

bool Botan::TLS::Protocol_Version::operator<= ( const Protocol_Version & other) const
inline
Returns
if this version is earlier than or equal to other

Definition at line 138 of file tls_version.h.

138{ return (*this == other || *this < other); }

◆ operator==()

bool Botan::TLS::Protocol_Version::operator== ( const Protocol_Version & other) const
inline
Returns
if this version is equal to other

Definition at line 113 of file tls_version.h.

113{ return (m_version == other.m_version); }

◆ operator>()

bool Botan::TLS::Protocol_Version::operator> ( const Protocol_Version & other) const
Returns
if this version is later than other

Definition at line 50 of file tls_version.cpp.

50 {
51 if(this->is_datagram_protocol() != other.is_datagram_protocol()) {
52 throw TLS_Exception(Alert::ProtocolVersion, "Version comparing " + to_string() + " with " + other.to_string());
53 }
54
55 if(this->is_datagram_protocol()) {
56 return m_version < other.m_version; // goes backwards
57 }
58
59 return m_version > other.m_version;
60}
std::string to_string() const

References is_datagram_protocol(), and to_string().

◆ operator>=()

bool Botan::TLS::Protocol_Version::operator>= ( const Protocol_Version & other) const
inline
Returns
if this version is later than or equal to other

Definition at line 128 of file tls_version.h.

128{ return (*this == other || *this > other); }

◆ to_string()

std::string Botan::TLS::Protocol_Version::to_string ( ) const
Returns
human-readable description of this version

Definition at line 16 of file tls_version.cpp.

16 {
17 const uint8_t maj = major_version();
18 const uint8_t min = minor_version();
19
20 if(maj == 3 && min == 0) {
21 return "SSL v3";
22 }
23
24 if(maj == 3 && min >= 1) { // TLS v1.x
25 return "TLS v1." + std::to_string(min - 1);
26 }
27
28 if(maj == 254) { // DTLS 1.x
29 return "DTLS v1." + std::to_string(255 - min);
30 }
31
32 // Some very new or very old protocol (or bogus data)
33 return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
34}
uint8_t minor_version() const
Definition tls_version.h:83

References major_version(), and minor_version().

Referenced by Botan::TLS::Channel_Impl_12::create_handshake_state(), and operator>().

◆ valid()

bool Botan::TLS::Protocol_Version::valid ( ) const
Returns
true if this is a valid protocol version

Definition at line 62 of file tls_version.cpp.

62 {
63 const uint8_t maj = major_version();
64 const uint8_t min = minor_version();
65
66 if(maj == 3 && min <= 4) {
67 // 3.0: SSLv3
68 // 3.1: TLS 1.0
69 // 3.2: TLS 1.1
70 // 3.3: TLS 1.2
71 // 3.4: TLS 1.3
72 return true;
73 }
74
75 if(maj == 254 && (min == 253 || min == 255)) {
76 // 254.253: DTLS 1.2
77 // 254.255: DTLS 1.0
78 return true;
79 }
80
81 return false;
82}

References major_version(), and minor_version().

◆ version_code()

uint16_t Botan::TLS::Protocol_Version::version_code ( ) const
inline
Returns
the version code

Definition at line 88 of file tls_version.h.

88{ return m_version; }

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