Coverage Report

Created: 2024-11-29 06:10

/src/botan/build/include/public/botan/tls_server_info.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* TLS Server Information
3
* (C) 2012 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_TLS_SERVER_INFO_H_
9
#define BOTAN_TLS_SERVER_INFO_H_
10
11
#include <botan/types.h>
12
#include <string>
13
14
namespace Botan::TLS {
15
16
/**
17
* Represents information known about a TLS server.
18
*/
19
class BOTAN_PUBLIC_API(2, 0) Server_Information final {
20
   public:
21
      /**
22
      * An empty server info - nothing known
23
      */
24
0
      Server_Information() : m_hostname(), m_service(), m_port(0) {}
25
26
      /**
27
      * @param hostname the host's DNS name, if known
28
      * @param port specifies the protocol port of the server (eg for
29
      *        TCP/UDP). Zero represents unknown.
30
      */
31
      Server_Information(std::string_view hostname, uint16_t port = 0) :
32
7.92k
            m_hostname(hostname), m_service(), m_port(port) {}
33
34
      /**
35
      * @param hostname the host's DNS name, if known
36
      * @param service is a text string of the service type
37
      *        (eg "https", "tor", or "git")
38
      * @param port specifies the protocol port of the server (eg for
39
      *        TCP/UDP). Zero represents unknown.
40
      */
41
      Server_Information(std::string_view hostname, std::string_view service, uint16_t port = 0) :
42
0
            m_hostname(hostname), m_service(service), m_port(port) {}
43
44
      /**
45
      * @return the host's DNS name, if known
46
      */
47
2.60k
      std::string hostname() const { return m_hostname; }
48
49
      /**
50
      * @return text string of the service type, e.g.,
51
      * "https", "tor", or "git"
52
      */
53
0
      std::string service() const { return m_service; }
54
55
      /**
56
      * @return the protocol port of the server, or zero if unknown
57
      */
58
0
      uint16_t port() const { return m_port; }
59
60
      /**
61
      * @return whether the hostname is known
62
      */
63
2.60k
      bool empty() const { return m_hostname.empty(); }
64
65
   private:
66
      std::string m_hostname, m_service;
67
      uint16_t m_port;
68
};
69
70
0
inline bool operator==(const Server_Information& a, const Server_Information& b) {
71
0
   return (a.hostname() == b.hostname()) && (a.service() == b.service()) && (a.port() == b.port());
72
0
}
73
74
0
inline bool operator!=(const Server_Information& a, const Server_Information& b) {
75
0
   return !(a == b);
76
0
}
77
78
0
inline bool operator<(const Server_Information& a, const Server_Information& b) {
79
0
   if(a.hostname() != b.hostname()) {
80
0
      return (a.hostname() < b.hostname());
81
0
   }
82
0
   if(a.service() != b.service()) {
83
0
      return (a.service() < b.service());
84
0
   }
85
0
   if(a.port() != b.port()) {
86
0
      return (a.port() < b.port());
87
0
   }
88
0
   return false;  // equal
89
0
}
90
91
}  // namespace Botan::TLS
92
93
#endif