Botan  2.1.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 Reference

#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

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 ( 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)) {}
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>(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 52 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.

Referenced by Botan::TLS::Policy::latest_supported_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.

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

uint8_t Botan::TLS::Protocol_Version::major_version ( ) const
inline
Returns
major version of the protocol version

Definition at line 77 of file tls_version.h.

References Botan::get_byte().

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

77 { return get_byte(0, m_version); }
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47
uint8_t Botan::TLS::Protocol_Version::minor_version ( ) const
inline
Returns
minor version of the protocol version

Definition at line 82 of file tls_version.h.

References Botan::get_byte().

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 Botan::TLS::write_record().

82 { return get_byte(1, m_version); }
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47
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.

123  {
124  return (m_version != other.m_version);
125  }
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  }
bool Botan::TLS::Protocol_Version::operator> ( const Protocol_Version other) const
Returns
if this version is later than other

Definition at line 39 of file tls_version.cpp.

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

40  {
41  if(this->is_datagram_protocol() != other.is_datagram_protocol())
42  throw TLS_Exception(Alert::PROTOCOL_VERSION,
43  "Version comparing " + to_string() +
44  " with " + other.to_string());
45 
46  if(this->is_datagram_protocol())
47  return m_version < other.m_version; // goes backwards
48 
49  return m_version > other.m_version;
50  }
std::string to_string() const
Definition: tls_version.cpp:16
bool is_datagram_protocol() const
Definition: tls_version.cpp:34
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  }
bool Botan::TLS::Protocol_Version::supports_aead_modes ( ) const

Definition at line 81 of file tls_version.cpp.

References DTLS_V12, and TLS_V12.

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

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

Definition at line 75 of file tls_version.cpp.

References DTLS_V12, and TLS_V12.

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 DTLS_V10, DTLS_V12, TLS_V11, and TLS_V12.

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

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

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

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

17  {
18  const uint8_t maj = major_version();
19  const uint8_t min = minor_version();
20 
21  if(maj == 3 && min == 0)
22  return "SSL v3";
23 
24  if(maj == 3 && min >= 1) // TLS v1.x
25  return "TLS v1." + std::to_string(min-1);
26 
27  if(maj == 254) // DTLS 1.x
28  return "DTLS v1." + std::to_string(255 - min);
29 
30  // Some very new or very old protocol (or bogus data)
31  return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
32  }
uint8_t minor_version() const
Definition: tls_version.h:82
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
uint8_t major_version() const
Definition: tls_version.h:77
T min(T a, T b)
Definition: ct_utils.h:180
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: