Coverage Report

Created: 2020-05-23 13:54

/src/botan/src/lib/tls/tls_version.cpp
Line
Count
Source (jump to first uncovered line)
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
124
   {
17
124
   const uint8_t maj = major_version();
18
124
   const uint8_t min = minor_version();
19
124
20
124
   if(maj == 3 && min == 0)
21
0
      return "SSL v3";
22
124
23
124
   if(maj == 3 && min >= 1) // TLS v1.x
24
19
      return "TLS v1." + std::to_string(min-1);
25
105
26
105
   if(maj == 254) // DTLS 1.x
27
9
      return "DTLS v1." + std::to_string(255 - min);
28
96
29
96
   // Some very new or very old protocol (or bogus data)
30
96
   return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
31
96
   }
32
33
bool Protocol_Version::is_datagram_protocol() const
34
540k
   {
35
540k
   return major_version() > 250;
36
540k
   }
37
38
bool Protocol_Version::operator>(const Protocol_Version& other) const
39
18.5k
   {
40
18.5k
   if(this->is_datagram_protocol() != other.is_datagram_protocol())
41
12
      throw TLS_Exception(Alert::PROTOCOL_VERSION,
42
12
                          "Version comparing " + to_string() +
43
12
                          " with " + other.to_string());
44
18.4k
45
18.4k
   if(this->is_datagram_protocol())
46
109
      return m_version < other.m_version; // goes backwards
47
18.3k
48
18.3k
   return m_version > other.m_version;
49
18.3k
   }
50
51
bool Protocol_Version::known_version() const
52
53.0k
   {
53
53.0k
   return (m_version == Protocol_Version::TLS_V10 ||
54
53.0k
           m_version == Protocol_Version::TLS_V11 ||
55
53.0k
           m_version == Protocol_Version::TLS_V12 ||
56
53.0k
           m_version == Protocol_Version::DTLS_V10 ||
57
53.0k
           m_version == Protocol_Version::DTLS_V12);
58
53.0k
   }
59
60
bool Protocol_Version::supports_negotiable_signature_algorithms() const
61
6.07k
   {
62
6.07k
   return (m_version != Protocol_Version::TLS_V10 &&
63
6.07k
           m_version != Protocol_Version::TLS_V11 &&
64
6.07k
           m_version != Protocol_Version::DTLS_V10);
65
6.07k
   }
66
67
bool Protocol_Version::supports_explicit_cbc_ivs() const
68
1.87k
   {
69
1.87k
   return (m_version != Protocol_Version::TLS_V10);
70
1.87k
   }
71
72
bool Protocol_Version::supports_ciphersuite_specific_prf() const
73
18.6k
   {
74
18.6k
   return (m_version != Protocol_Version::TLS_V10 &&
75
18.6k
           m_version != Protocol_Version::TLS_V11 &&
76
18.6k
           m_version != Protocol_Version::DTLS_V10);
77
18.6k
   }
78
79
bool Protocol_Version::supports_aead_modes() const
80
4.92M
   {
81
4.92M
   return (m_version != Protocol_Version::TLS_V10 &&
82
4.92M
           m_version != Protocol_Version::TLS_V11 &&
83
4.92M
           m_version != Protocol_Version::DTLS_V10);
84
4.92M
   }
85
86
}
87
88
}