Botan 3.11.0
Crypto and TLS for C&
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 34 of file tls_version.h.

Constructor & Destructor Documentation

◆ Protocol_Version() [1/4]

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

◆ Protocol_Version() [2/4]

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

Definition at line 56 of file tls_version.h.

56: 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 61 of file tls_version.h.

61 : // NOLINT(*-explicit-conversions)
62 Protocol_Version(static_cast<uint16_t>(named_version)) {}

References Protocol_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 68 of file tls_version.h.

68 :
69 Protocol_Version(static_cast<uint16_t>((static_cast<uint16_t>(major) << 8) | minor)) {}

References Protocol_Version().

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 63 of file tls_version.cpp.

63 {
64 return (!is_datagram_protocol() && *this >= Protocol_Version::TLS_V13) ||
65 (is_datagram_protocol() && *this >= Protocol_Version::DTLS_V13);
66}

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 102 of file tls_version.cpp.

102 {
103#if defined(BOTAN_HAS_TLS_13)
104 if(m_version == static_cast<uint16_t>(Protocol_Version::TLS_V13)) {
105 return true;
106 }
107#endif
108
109#if defined(BOTAN_HAS_TLS_12)
110 if(m_version == static_cast<uint16_t>(Protocol_Version::TLS_V12)) {
111 return true;
112 }
113 if(m_version == static_cast<uint16_t>(Protocol_Version::DTLS_V12)) {
114 return true;
115 }
116#endif
117
118 return false;
119}

◆ latest_dtls_version()

Protocol_Version Botan::TLS::Protocol_Version::latest_dtls_version ( )
static

Returns the latest version of the DTLS protocol known to the library and available in the current build.

Returns
latest known DTLS version

Definition at line 26 of file tls_version.cpp.

26 {
27#if defined(BOTAN_HAS_TLS_12)
28 return Protocol_Version::DTLS_V12;
29#else
30 throw Not_Implemented("This build contains no usable DTLS version");
31#endif
32}

References Protocol_Version().

◆ latest_tls_version()

Protocol_Version Botan::TLS::Protocol_Version::latest_tls_version ( )
static

Returns the latest version of the TLS protocol known to the library and available in the current build.

Returns
latest known TLS version

Definition at line 16 of file tls_version.cpp.

16 {
17#if defined(BOTAN_HAS_TLS_13)
18 return Protocol_Version::TLS_V13;
19#elif defined(BOTAN_HAS_TLS_12)
20 return Protocol_Version::TLS_V12;
21#else
22 throw Not_Implemented("This build contains no usable TLS version");
23#endif
24}

References Protocol_Version().

◆ 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 89 of file tls_version.h.

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

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), 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 128 of file tls_version.h.

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

References Protocol_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 143 of file tls_version.h.

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

References Protocol_Version().

◆ 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 148 of file tls_version.h.

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

References Protocol_Version().

◆ operator==()

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

Definition at line 123 of file tls_version.h.

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

References Protocol_Version().

◆ operator>()

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

Definition at line 68 of file tls_version.cpp.

68 {
69 if(this->is_datagram_protocol() != other.is_datagram_protocol()) {
70 throw TLS_Exception(Alert::ProtocolVersion, "Version comparing " + to_string() + " with " + other.to_string());
71 }
72
73 if(this->is_datagram_protocol()) {
74 return m_version < other.m_version; // goes backwards
75 }
76
77 return m_version > other.m_version;
78}
std::string to_string() const

References is_datagram_protocol(), Protocol_Version(), 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 138 of file tls_version.h.

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

References Protocol_Version().

◆ to_string()

std::string Botan::TLS::Protocol_Version::to_string ( ) const

Generate a human readable version string.

for instance "TLS v1.1" or "DTLS v1.0".

Returns
human-readable description of this version

Definition at line 34 of file tls_version.cpp.

34 {
35 const uint8_t maj = major_version();
36 const uint8_t min = minor_version();
37
38 if(maj == 3 && min == 0) {
39 return "SSL v3";
40 }
41
42 if(maj == 3 && min >= 1) { // TLS v1.x
43 return "TLS v1." + std::to_string(min - 1);
44 }
45
46 if(maj == 254) { // DTLS 1.x
47 return "DTLS v1." + std::to_string(255 - min);
48 }
49
50 // Some very new or very old protocol (or bogus data)
51 return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
52}
uint8_t minor_version() const
Definition tls_version.h:89

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 80 of file tls_version.cpp.

80 {
81 const uint8_t maj = major_version();
82 const uint8_t min = minor_version();
83
84 if(maj == 3 && min <= 4) {
85 // 3.0: SSLv3
86 // 3.1: TLS 1.0
87 // 3.2: TLS 1.1
88 // 3.3: TLS 1.2
89 // 3.4: TLS 1.3
90 return true;
91 }
92
93 if(maj == 254 && (min == 253 || min == 255)) {
94 // 254.253: DTLS 1.2
95 // 254.255: DTLS 1.0
96 return true;
97 }
98
99 return false;
100}

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 94 of file tls_version.h.

94{ return m_version; }

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