GCC Code Coverage Report


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

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