GCC Code Coverage Report


Directory: src/gate/
File: src/gate/net/cxx_sslsessions.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 55 0.0%
Functions: 0 9 0.0%
Branches: 0 46 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28 #include "gate/net/sslsessions.hpp"
29
30 #include "gate/exceptions.hpp"
31
32 namespace gate
33 {
34 namespace net
35 {
36
37 SslSession::SslSession(TypeEnum sslType, bool_t serverSide, Blob const& certificate, Blob const& privateKey)
38 : impl(gate_ssl_session_t())
39 {
40 gate_ssl_session_params_t params;
41 params.session_version = (gate_enumint_t)sslType;
42 params.server_side = serverSide;
43 params.certificate = certificate.data();
44 params.certificate_length = certificate.length();
45 params.privatekey = privateKey.data();
46 params.privatekey_length = privateKey.length();
47 result_t result = gate_ssl_session_create(&params, &this->impl);
48 GATEXX_CHECK_EXCEPTION(result);
49 }
50 SslSession::~SslSession() noexcept
51 {
52 gate_ssl_session_destroy(this->impl);
53 }
54
55 bool SslSession::isNegotiated()
56 {
57 bool ret = false;
58 result_t result = gate_ssl_session_is_negotiated(this->impl, &ret);
59 GATEXX_CHECK_EXCEPTION(result);
60 return ret;
61 }
62 void SslSession::negotiate()
63 {
64 result_t result = gate_ssl_session_negotiate(this->impl);
65 GATEXX_CHECK_EXCEPTION(result);
66 }
67
68 size_t SslSession::writeData(char const* plainData, size_t plainDataLength)
69 {
70 gate_size_t written = 0;
71 result_t result = gate_ssl_session_write(this->impl, plainData, plainDataLength, &written);
72 GATEXX_CHECK_EXCEPTION(result);
73 return written;
74 }
75 size_t SslSession::getEncodedData(char* encodedData, size_t encodedDataLength)
76 {
77 gate_size_t returned = 0;
78 result_t result = gate_ssl_session_get_encoded_data(this->impl, encodedData, encodedDataLength, &returned);
79 GATEXX_CHECK_EXCEPTION(result);
80 return returned;
81 }
82
83 size_t SslSession::addEncodedData(char const* plainData, size_t plainDataLength)
84 {
85 gate_size_t written = 0;
86 result_t result = gate_ssl_session_add_encoded_data(this->impl, plainData, plainDataLength, &written);
87 GATEXX_CHECK_EXCEPTION(result);
88 return written;
89 }
90 size_t SslSession::readData(char* encodedData, size_t encodedDataLength)
91 {
92 gate_size_t returned = 0;
93 result_t result = gate_ssl_session_read(this->impl, encodedData, encodedDataLength, &returned);
94 GATEXX_CHECK_EXCEPTION(result);
95 return returned;
96 }
97
98
99 Stream SslStream::create(Stream& transportStream, SslSession::TypeEnum type, bool_t serverSide, Blob const& certificate, Blob const& privateKey)
100 {
101 gate_ssl_session_params_t params;
102 params.session_version = (gate_enumint_t)type;
103 params.server_side = serverSide;
104 params.certificate = certificate.data();
105 params.certificate_length = certificate.length();
106 params.privatekey = privateKey.data();
107 params.privatekey_length = privateKey.length();
108
109 gate_stream_t* ptr_sslstream = NULL;
110 result_t result = gate_ssl_stream_create(&params, transportStream.c_impl(), &ptr_sslstream);
111 GATEXX_CHECK_EXCEPTION(result);
112 Stream ret(ptr_sslstream);
113 return ret;
114 }
115
116 } // end of namespace net
117 } // end of namespace gate
118