• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 21943010187

12 Feb 2026 10:33AM UTC coverage: 90.061% (-0.006%) from 90.067%
21943010187

Pull #5318

github

web-flow
Merge 005a803db into f97d7db3f
Pull Request #5318: Allow disabling TLS 1.2 at Build Time

102245 of 113528 relevant lines covered (90.06%)

11733046.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.47
/src/lib/tls/tls_version.cpp
1
/*
2
* TLS Protocol Version Management
3
* (C) 2012 Jack Lloyd
4
*     2021 Elektrobit Automotive GmbH
5
*     2022 René Meusel, Hannes Rantzsch - neXenio GmbH
6
*
7
* Botan is released under the Simplified BSD License (see license.txt)
8
*/
9

10
#include <botan/tls_version.h>
11

12
#include <botan/tls_exceptn.h>
13

14
namespace Botan::TLS {
15

16
Protocol_Version Protocol_Version::latest_tls_version() {
×
17
#if defined(BOTAN_HAS_TLS_13)
18
   return Protocol_Version::TLS_V13;
×
19
#elif defined(BOTAN_HAS_TLS_12)
20
   return Protocol_Version::TLS_V12;
21
#else
22
   throw Not_Implemented("This build contains no usable TLS version");
23
#endif
24
}
25

26
Protocol_Version Protocol_Version::latest_dtls_version() {
2✔
27
#if defined(BOTAN_HAS_TLS_12)
28
   return Protocol_Version::DTLS_V12;
2✔
29
#else
30
   throw Not_Implemented("This build contains no usable DTLS version");
31
#endif
32
}
33

34
std::string Protocol_Version::to_string() const {
4,010✔
35
   const uint8_t maj = major_version();
4,010✔
36
   const uint8_t min = minor_version();
4,010✔
37

38
   if(maj == 3 && min == 0) {
4,010✔
39
      return "SSL v3";
×
40
   }
41

42
   if(maj == 3 && min >= 1) {  // TLS v1.x
4,010✔
43
      return "TLS v1." + std::to_string(min - 1);
5,644✔
44
   }
45

46
   if(maj == 254) {  // DTLS 1.x
1,188✔
47
      return "DTLS v1." + std::to_string(255 - min);
2,374✔
48
   }
49

50
   // Some very new or very old protocol (or bogus data)
51
   return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
4✔
52
}
53

54
bool Protocol_Version::is_datagram_protocol() const {
1,799,131✔
55
   return major_version() > 250;
1,799,131✔
56
}
57

58
bool Protocol_Version::is_pre_tls_13() const {
624,991✔
59
   return (!is_datagram_protocol() && *this <= Protocol_Version::TLS_V12) ||
864,329✔
60
          (is_datagram_protocol() && *this <= Protocol_Version::DTLS_V12);
324,910✔
61
}
62

63
bool Protocol_Version::is_tls_13_or_later() const {
1,180✔
64
   return (!is_datagram_protocol() && *this >= Protocol_Version::TLS_V13) ||
1,646✔
65
          (is_datagram_protocol() && *this >= Protocol_Version::DTLS_V13);
466✔
66
}
67

68
bool Protocol_Version::operator>(const Protocol_Version& other) const {
162,276✔
69
   if(this->is_datagram_protocol() != other.is_datagram_protocol()) {
162,276✔
70
      throw TLS_Exception(Alert::ProtocolVersion, "Version comparing " + to_string() + " with " + other.to_string());
×
71
   }
72

73
   if(this->is_datagram_protocol()) {
162,276✔
74
      return m_version < other.m_version;  // goes backwards
858✔
75
   }
76

77
   return m_version > other.m_version;
161,418✔
78
}
79

80
bool Protocol_Version::valid() const {
3,762✔
81
   const uint8_t maj = major_version();
3,762✔
82
   const uint8_t min = minor_version();
3,762✔
83

84
   if(maj == 3 && min <= 4) {
3,762✔
85
      // 3.0: SSLv3
86
      // 3.1: TLS 1.0
87
      // 3.2: TLS 1.1
88
      // 3.3: TLS 1.2
89
      // 3.4: TLS 1.3
90
      return true;
91
   }
92

93
   if(maj == 254 && (min == 253 || min == 255)) {
1,852✔
94
      // 254.253: DTLS 1.2
95
      // 254.255: DTLS 1.0
96
      return true;
97
   }
98

99
   return false;
100
}
101

102
bool Protocol_Version::known_version() const {
20,045✔
103
#if defined(BOTAN_HAS_TLS_13)
104
   if(m_version == static_cast<uint16_t>(Protocol_Version::TLS_V13)) {
20,045✔
105
      return true;
106
   }
107
#endif
108

109
#if defined(BOTAN_HAS_TLS_12)
110
   if(m_version == static_cast<uint16_t>(Protocol_Version::TLS_V12)) {
14,974✔
111
      return true;
112
   }
113
   if(m_version == static_cast<uint16_t>(Protocol_Version::DTLS_V12)) {
4,936✔
114
      return true;
4,039✔
115
   }
116
#endif
117

118
   return false;
119
}
120

121
}  // namespace Botan::TLS
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc