Botan  2.6.0
Crypto and TLS for C++11
tls_version.cpp
Go to the documentation of this file.
1 /*
2 * TLS Protocol Version Management
3 * (C) 2012 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/tls_version.h>
9 #include <botan/tls_exceptn.h>
10 
11 namespace Botan {
12 
13 namespace TLS {
14 
15 std::string Protocol_Version::to_string() const
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  }
32 
34  {
35  return major_version() == 254;
36  }
37 
39  {
40  if(this->is_datagram_protocol() != other.is_datagram_protocol())
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  }
50 
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  }
59 
61  {
62  return (m_version == Protocol_Version::TLS_V12 ||
63  m_version == Protocol_Version::DTLS_V12);
64  }
65 
67  {
68  return (m_version == Protocol_Version::TLS_V11 ||
69  m_version == Protocol_Version::TLS_V12 ||
70  m_version == Protocol_Version::DTLS_V10 ||
71  m_version == Protocol_Version::DTLS_V12);
72  }
73 
75  {
76  return (m_version == Protocol_Version::TLS_V12 ||
77  m_version == Protocol_Version::DTLS_V12);
78  }
79 
81  {
82  return (m_version == Protocol_Version::TLS_V12 ||
83  m_version == Protocol_Version::DTLS_V12);
84  }
85 
86 }
87 
88 }
uint8_t minor_version() const
Definition: tls_version.h:82
bool operator>(const Protocol_Version &other) const
Definition: tls_version.cpp:38
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:145
bool supports_negotiable_signature_algorithms() const
Definition: tls_version.cpp:60
std::string to_string() const
Definition: tls_version.cpp:15
bool supports_explicit_cbc_ivs() const
Definition: tls_version.cpp:66
Definition: alg_id.cpp:13
bool supports_ciphersuite_specific_prf() const
Definition: tls_version.cpp:74
uint8_t major_version() const
Definition: tls_version.h:77