Botan  2.4.0
Crypto and TLS for C++11
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 (Version_Code named_version)
 
 Protocol_Version (uint8_t major, uint8_t minor)
 
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
 

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/3]

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

Definition at line 49 of file tls_version.h.

49 : m_version(0) {}

◆ Protocol_Version() [2/3]

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

Definition at line 54 of file tls_version.h.

54  :
55  m_version(static_cast<uint16_t>(named_version)) {}

◆ Protocol_Version() [3/3]

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

Definition at line 61 of file tls_version.h.

61  :
62  m_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.

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

Referenced by Botan::TLS::Server::Server().

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

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

◆ major_version()

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

◆ minor_version()

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

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

References Botan::operator>().

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

◆ operator==()

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

Definition at line 114 of file tls_version.h.

115  {
116  return (m_version == other.m_version);
117  }

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

References is_datagram_protocol(), Botan::TLS::Alert::PROTOCOL_VERSION, and to_string().

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
Definition: tls_version.cpp:15

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

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

◆ supports_aead_modes()

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

Definition at line 80 of file tls_version.cpp.

References DTLS_V12, and TLS_V12.

Referenced by Botan::TLS::Policy::ciphersuite_list().

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

References DTLS_V12, and TLS_V12.

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

References DTLS_V10, DTLS_V12, TLS_V11, and TLS_V12.

Referenced by Botan::TLS::Connection_Cipher_State::Connection_Cipher_State().

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

References major_version(), minor_version(), and Botan::ASN1::to_string().

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

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:82
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
uint8_t major_version() const
Definition: tls_version.h:77

◆ valid()

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

Definition at line 67 of file tls_version.h.

67 { return (m_version != 0); }

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