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

#include <tls_version.h>

Public Types

enum  Version_Code {
  TLS_V10 = 0x0301 , TLS_V11 = 0x0302 , TLS_V12 = 0x0303 , DTLS_V10 = 0xFEFF ,
  DTLS_V12 = 0xFEFD
}
 

Public Member Functions

bool is_datagram_protocol () 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
 
 Protocol_Version ()
 
 Protocol_Version (uint16_t code)
 
 Protocol_Version (uint8_t major, uint8_t minor)
 
 Protocol_Version (Version_Code named_version)
 
bool supports_aead_modes () const
 
bool supports_ciphersuite_specific_prf () const
 
bool supports_explicit_cbc_ivs () const
 
bool supports_negotiable_signature_algorithms () const
 
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 21 of file tls_version.h.

Member Enumeration Documentation

◆ Version_Code

Enumerator
TLS_V10 
TLS_V11 
TLS_V12 
DTLS_V10 
DTLS_V12 

Definition at line 24 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 :
57 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 63 of file tls_version.h.

63 :
64 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

◆ known_version()

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

Definition at line 51 of file tls_version.cpp.

52 {
53 return (m_version == Protocol_Version::TLS_V10 ||
54 m_version == Protocol_Version::TLS_V11 ||
55 m_version == Protocol_Version::TLS_V12 ||
56 m_version == Protocol_Version::DTLS_V10 ||
57 m_version == Protocol_Version::DTLS_V12);
58 }

References DTLS_V10, DTLS_V12, TLS_V10, TLS_V11, and TLS_V12.

◆ latest_dtls_version()

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

Definition at line 44 of file tls_version.h.

45 {
47 }

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

37 {
39 }

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle().

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

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

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

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

130 {
131 return (m_version != other.m_version);
132 }

◆ operator==()

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

Definition at line 121 of file tls_version.h.

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

◆ operator>()

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

Definition at line 38 of file tls_version.cpp.

39 {
40 if(this->is_datagram_protocol() != other.is_datagram_protocol())
41 throw TLS_Exception(Alert::PROTOCOL_VERSION,
42 "Version comparing " + to_string() +
43 " with " + other.to_string());
44
45 if(this->is_datagram_protocol())
46 return m_version < other.m_version; // goes backwards
47
48 return m_version > other.m_version;
49 }
std::string to_string() const

References is_datagram_protocol(), Botan::TLS::Alert::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 142 of file tls_version.h.

143 {
144 return (*this == other || *this > other);
145 }

◆ supports_aead_modes()

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

Definition at line 79 of file tls_version.cpp.

80 {
81 return (m_version != Protocol_Version::TLS_V10 &&
82 m_version != Protocol_Version::TLS_V11 &&
83 m_version != Protocol_Version::DTLS_V10);
84 }

References DTLS_V10, TLS_V10, and TLS_V11.

Referenced by Botan::TLS::Ciphersuite::usable_in_version().

◆ supports_ciphersuite_specific_prf()

bool Botan::TLS::Protocol_Version::supports_ciphersuite_specific_prf ( ) const
Returns
true if this version uses a ciphersuite specific PRF

Definition at line 72 of file tls_version.cpp.

73 {
74 return (m_version != Protocol_Version::TLS_V10 &&
75 m_version != Protocol_Version::TLS_V11 &&
76 m_version != Protocol_Version::DTLS_V10);
77 }

References DTLS_V10, TLS_V10, and TLS_V11.

Referenced by Botan::TLS::Handshake_Hash::final().

◆ supports_explicit_cbc_ivs()

bool Botan::TLS::Protocol_Version::supports_explicit_cbc_ivs ( ) const
Returns
true if this version uses explicit IVs for block ciphers

Definition at line 67 of file tls_version.cpp.

68 {
69 return (m_version != Protocol_Version::TLS_V10);
70 }

References TLS_V10.

Referenced by Botan::TLS::Ciphersuite::nonce_bytes_from_record(), and Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::TLS_CBC_HMAC_AEAD_Mode().

◆ supports_negotiable_signature_algorithms()

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

◆ to_string()

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

Definition at line 15 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 if(maj == 3 && min >= 1) // TLS v1.x
24 return "TLS v1." + std::to_string(min-1);
25
26 if(maj == 254) // DTLS 1.x
27 return "DTLS v1." + std::to_string(255 - min);
28
29 // Some very new or very old protocol (or bogus data)
30 return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
31 }
uint8_t minor_version() const
Definition tls_version.h:84

References major_version(), and minor_version().

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

◆ valid()

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

Definition at line 69 of file tls_version.h.

69{ return (m_version != 0); }

◆ version_code()

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

Definition at line 89 of file tls_version.h.

89{ return m_version; }

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