src/openssl/src/openssl_stream.cpp

95.5% Lines (42/44) 100.0% List of functions (12/12) 60.9% Branches (14/23)
openssl_stream.cpp
f(x) Functions (12)
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco ([email protected])
3 // Copyright (c) 2026 Michael Vandeberg
4 // Copyright (c) 2026 Steve Gerbino
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // Official repository: https://github.com/cppalliance/corosio
10 //
11
12 #include <boost/corosio/openssl_stream.hpp>
13 #include <boost/corosio/detail/config.hpp>
14
15 #include "detail/engine.hpp"
16 #include "src/tls/detail/engine_driver.hpp"
17
18 // The driver logic lives once in detail::engine_driver (see its
19 // header for the architecture); this TU only binds it to the OpenSSL
20 // engine and plumbs the public stream surface through.
21
22 namespace boost::corosio {
23
24 // Readable failure if the engine drifts from the driver's surface.
25 static_assert(detail::tls_engine<detail::openssl::engine>);
26
27 struct openssl_stream::implementation
28 : detail::engine_driver<detail::openssl::engine>
29 {
30 using engine_driver::engine_driver;
31 };
32
33 openssl_stream::implementation*
34 2676x openssl_stream::make_implementation(capy::any_stream& stream, tls_context const& ctx)
35 {
36
2/4
✓ Branch 2 → 3 taken 2676 times.
✓ Branch 4 → 5 taken 2676 times.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
2676x auto* p = new implementation(stream, ctx);
37
38
1/1
✓ Branch 8 → 9 taken 2676 times.
2676x auto ec = p->engine().init(p->context());
39
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 15 taken 2676 times.
2676x if (ec)
40 {
41 delete p;
42 return nullptr;
43 }
44
45 2676x return p;
46 }
47
48 2678x openssl_stream::~openssl_stream()
49 {
50
2/2
✓ Branch 2 → 3 taken 2675 times.
✓ Branch 2 → 5 taken 3 times.
2678x delete impl_;
51 2678x }
52
53 2x openssl_stream::openssl_stream(openssl_stream&& other) noexcept
54 2x : stream_(std::move(other.stream_))
55 2x , impl_(other.impl_)
56 {
57 2x other.impl_ = nullptr;
58
1/2
✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 7 not taken.
2x if (impl_)
59 2x impl_->rebind_stream(stream_);
60 2x }
61
62 openssl_stream&
63 1x openssl_stream::operator=(openssl_stream&& other) noexcept
64 {
65
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 10 not taken.
1x if (this != &other)
66 {
67
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 6 not taken.
1x delete impl_;
68 1x stream_ = std::move(other.stream_);
69 1x impl_ = other.impl_;
70 1x other.impl_ = nullptr;
71
1/2
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 10 not taken.
1x if (impl_)
72 1x impl_->rebind_stream(stream_);
73 }
74 1x return *this;
75 }
76
77 capy::io_task<std::size_t>
78
1/1
✓ Branch 6 → 7 taken 30057 times.
30057x openssl_stream::do_read_some(
79 capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers)
80 {
81 co_return co_await impl_->do_read_some(buffers);
82 60114x }
83
84 capy::io_task<std::size_t>
85
1/1
✓ Branch 6 → 7 taken 29944 times.
29944x openssl_stream::do_write_some(
86 capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers)
87 {
88 co_return co_await impl_->do_write_some(buffers);
89 59888x }
90
91 capy::io_task<>
92
1/1
✓ Branch 5 → 6 taken 2047 times.
2047x openssl_stream::handshake(tls_role role)
93 {
94 co_return co_await impl_->do_handshake(role);
95 4094x }
96
97 capy::io_task<>
98
1/1
✓ Branch 5 → 6 taken 144 times.
144x openssl_stream::shutdown()
99 {
100 co_return co_await impl_->do_shutdown();
101 288x }
102
103 void
104 60x openssl_stream::reset()
105 {
106 60x impl_->reset();
107 60x }
108
109 void
110 13x openssl_stream::set_hostname(std::string_view hostname)
111 {
112 13x impl_->set_hostname(hostname);
113 13x }
114
115 std::string_view
116 1x openssl_stream::name() const noexcept
117 {
118 1x return "openssl";
119 }
120
121 std::string_view
122 3x openssl_stream::alpn_protocol() const noexcept
123 {
124 3x return impl_->alpn_protocol();
125 }
126
127 } // namespace boost::corosio
128