Coverage Report

Created: 2021-05-04 09:02

/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
0
   {
17
0
   const uint8_t maj = major_version();
18
0
   const uint8_t min = minor_version();
19
20
0
   if(maj == 3 && min == 0)
21
0
      return "SSL v3";
22
23
0
   if(maj == 3 && min >= 1) // TLS v1.x
24
0
      return "TLS v1." + std::to_string(min-1);
25
26
0
   if(maj == 254) // DTLS 1.x
27
0
      return "DTLS v1." + std::to_string(255 - min);
28
29
   // Some very new or very old protocol (or bogus data)
30
0
   return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
31
0
   }
32
33
bool Protocol_Version::is_datagram_protocol() const
34
474k
   {
35
474k
   return major_version() > 250;
36
474k
   }
37
38
bool Protocol_Version::operator>(const Protocol_Version& other) const
39
0
   {
40
0
   if(this->is_datagram_protocol() != other.is_datagram_protocol())
41
0
      throw TLS_Exception(Alert::PROTOCOL_VERSION,
42
0
                          "Version comparing " + to_string() +
43
0
                          " with " + other.to_string());
44
45
0
   if(this->is_datagram_protocol())
46
0
      return m_version < other.m_version; // goes backwards
47
48
0
   return m_version > other.m_version;
49
0
   }
50
51
bool Protocol_Version::known_version() const
52
56.1k
   {
53
56.1k
   return (m_version == Protocol_Version::TLS_V12 ||
54
56.0k
           m_version == Protocol_Version::DTLS_V12);
55
56.1k
   }
56
57
}
58
59
}