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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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

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

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

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

36
bool Protocol_Version::is_datagram_protocol() const { return major_version() > 250; }
1,344,910✔
37

38
bool Protocol_Version::is_pre_tls_13() const {
366,323✔
39
   return (!is_datagram_protocol() && *this <= Protocol_Version::TLS_V12) ||
571,512✔
40
          (is_datagram_protocol() && *this <= Protocol_Version::DTLS_V12);
275,874✔
41
}
42

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

48
bool Protocol_Version::operator>(const Protocol_Version& other) const {
140,495✔
49
   if(this->is_datagram_protocol() != other.is_datagram_protocol()) {
140,495✔
50
      throw TLS_Exception(Alert::ProtocolVersion, "Version comparing " + to_string() + " with " + other.to_string());
×
51
   }
52

53
   if(this->is_datagram_protocol()) {
140,495✔
54
      return m_version < other.m_version;  // goes backwards
769✔
55
   }
56

57
   return m_version > other.m_version;
139,726✔
58
}
59

60
bool Protocol_Version::valid() const {
3,586✔
61
   const uint8_t maj = major_version();
3,586✔
62
   const uint8_t min = minor_version();
3,586✔
63

64
   if(maj == 3 && min <= 4) {
3,586✔
65
      // 3.0: SSLv3
66
      // 3.1: TLS 1.0
67
      // 3.2: TLS 1.1
68
      // 3.3: TLS 1.2
69
      // 3.4: TLS 1.3
70
      return true;
71
   }
72

73
   if(maj == 254 && (min == 253 || min == 255)) {
1,715✔
74
      // 254.253: DTLS 1.2
75
      // 254.255: DTLS 1.0
76
      return true;
426✔
77
   }
78

79
   return false;
80
}
81

82
bool Protocol_Version::known_version() const {
19,047✔
83
   return (m_version == static_cast<uint16_t>(Protocol_Version::TLS_V12) ||
19,047✔
84
#if defined(BOTAN_HAS_TLS_13)
85
           m_version == static_cast<uint16_t>(Protocol_Version::TLS_V13) ||
19,047✔
86
#endif
87
           m_version == static_cast<uint16_t>(Protocol_Version::DTLS_V12));
19,047✔
88
}
89

90
}  // 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