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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

93.94
/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
std::string Protocol_Version::to_string() const {
3,789✔
17
   const uint8_t maj = major_version();
3,789✔
18
   const uint8_t min = minor_version();
3,789✔
19

20
   if(maj == 3 && min == 0)
3,789✔
21
      return "SSL v3";
×
22

23
   if(maj == 3 && min >= 1)  // TLS v1.x
3,789✔
24
      return "TLS v1." + std::to_string(min - 1);
5,318✔
25

26
   if(maj == 254)  // DTLS 1.x
1,130✔
27
      return "DTLS v1." + std::to_string(255 - min);
2,258✔
28

29
   // Some very new or very old protocol (or bogus data)
30
   return "Unknown " + std::to_string(maj) + "." + std::to_string(min);
2✔
31
}
32

33
bool Protocol_Version::is_datagram_protocol() const { return major_version() > 250; }
1,344,248✔
34

35
bool Protocol_Version::is_pre_tls_13() const {
366,005✔
36
   return (!is_datagram_protocol() && *this <= Protocol_Version::TLS_V12) ||
570,855✔
37
          (is_datagram_protocol() && *this <= Protocol_Version::DTLS_V12);
275,196✔
38
}
39

40
bool Protocol_Version::is_tls_13_or_later() const {
1,137✔
41
   return (!is_datagram_protocol() && *this >= Protocol_Version::TLS_V13) ||
1,580✔
42
          (is_datagram_protocol() && *this >= Protocol_Version::DTLS_V13);
443✔
43
}
44

45
bool Protocol_Version::operator>(const Protocol_Version& other) const {
140,492✔
46
   if(this->is_datagram_protocol() != other.is_datagram_protocol())
140,492✔
47
      throw TLS_Exception(Alert::ProtocolVersion, "Version comparing " + to_string() + " with " + other.to_string());
×
48

49
   if(this->is_datagram_protocol())
140,492✔
50
      return m_version < other.m_version;  // goes backwards
766✔
51

52
   return m_version > other.m_version;
139,726✔
53
}
54

55
bool Protocol_Version::valid() const {
3,586✔
56
   const uint8_t maj = major_version();
3,586✔
57
   const uint8_t min = minor_version();
3,586✔
58

59
   if(maj == 3 && min <= 4)
3,586✔
60
      // 3.0: SSLv3
61
      // 3.1: TLS 1.0
62
      // 3.2: TLS 1.1
63
      // 3.3: TLS 1.2
64
      // 3.4: TLS 1.3
65
      return true;
66

67
   if(maj == 254 && (min == 253 || min == 255))
1,715✔
68
      // 254.253: DTLS 1.2
69
      // 254.255: DTLS 1.0
70
      return true;
426✔
71

72
   return false;
73
}
74

75
bool Protocol_Version::known_version() const {
19,047✔
76
   return (m_version == static_cast<uint16_t>(Protocol_Version::TLS_V12) ||
19,047✔
77
#if defined(BOTAN_HAS_TLS_13)
78
           m_version == static_cast<uint16_t>(Protocol_Version::TLS_V13) ||
19,047✔
79
#endif
80
           m_version == static_cast<uint16_t>(Protocol_Version::DTLS_V12));
19,047✔
81
}
82

83
}
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