Botan  2.19.1
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 (uint16_t code)
 
 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
 
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

Enumerator
TLS_V10 
TLS_V11 
TLS_V12 
DTLS_V10 
DTLS_V12 

Definition at line 24 of file tls_version.h.

Constructor & Destructor Documentation

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

Definition at line 49 of file tls_version.h.

49 : m_version(0) {}
Botan::TLS::Protocol_Version::Protocol_Version ( uint16_t  code)
inlineexplicit

Definition at line 51 of file tls_version.h.

51 : m_version(code) {}
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)) {}
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

bool Botan::TLS::Protocol_Version::is_datagram_protocol ( ) const
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.

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.

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.

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

uint8_t Botan::TLS::Protocol_Version::major_version ( ) const
inline
uint8_t Botan::TLS::Protocol_Version::minor_version ( ) const
inline
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  }
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  }
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
bool is_datagram_protocol() const
Definition: tls_version.cpp:33
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  }
bool Botan::TLS::Protocol_Version::supports_aead_modes ( ) const
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.

References DTLS_V10, TLS_V10, and TLS_V11.

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

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.

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

68  {
69  return (m_version != Protocol_Version::TLS_V10);
70  }
bool Botan::TLS::Protocol_Version::supports_negotiable_signature_algorithms ( ) const
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::Client_Hello::Client_Hello(), Botan::TLS::Channel::create_handshake_state(), and operator>().

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
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
uint8_t major_version() const
Definition: tls_version.h:79
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); }
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: