GCC Code Coverage Report


Directory: ./
File: pdserv/src/TLS.h
Date: 2025-08-17 04:10:43
Exec Total Coverage
Lines: 2 3 66.7%
Branches: 0 0 -%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright 2016 Richard Hacker (lerichi at gmx dot net)
4 *
5 * This file is part of the pdserv library.
6 *
7 * The pdserv library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or (at
10 * your option) any later version.
11 *
12 * The pdserv library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the pdserv library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22 #ifndef TLS_H
23 #define TLS_H
24
25 #include <set>
26 #include <map>
27 #include <list>
28 #include <string>
29 #include <gnutls/x509.h>
30 #include "PThread.h"
31
32 // Maximum count of TLS session memory
33 #define TLS_DB_SIZE 100
34
35 // Maximum size of TLS session data
36 #define TLS_DB_MAX_ENTRY_SIZE 5000
37
38 struct datum_string: std::basic_string<unsigned char> {
39 datum_string(size_t len = 0);
40 datum_string(const gnutls_datum_t& value);
41 datum_string(const pointer data, size_t len);
42 datum_string(const char* hexdata, size_t len = ~0U);
43
44 operator std::string() const;
45 operator gnutls_datum_t() const;
46 };
47
48 314 struct Blacklist: std::set<datum_string> {};
49
50 157 class TlsSessionDB {
51 public:
52 TlsSessionDB(pthread::Mutex* sem, size_t max);
53
54 int store(const gnutls_datum_t& key, const gnutls_datum_t& value);
55 int erase(const gnutls_datum_t& key);
56 gnutls_datum_t retrieve(const gnutls_datum_t& key);
57
58 private:
59 pthread::Mutex* const mutex;
60 const size_t maxSize;
61
62 typedef std::map<datum_string, datum_string> map_type;
63 map_type map;
64
65 std::list<map_type::iterator> list;
66 };
67
68 struct TlsDeleter
69 {
70 void operator()(gnutls_session_t);
71 void operator()(gnutls_dh_params_t);
72 void operator()(gnutls_priority_t);
73 void operator()(gnutls_x509_crt_t c);
74 void operator()(gnutls_certificate_credentials_t cc);
75 };
76
77 #endif //TLS_H
78