src/openssl/src/openssl_stream.cpp

100.0% Lines (39/39) 100.0% List of functions (12/12) 64.7% Branches (11/17)
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 4191x openssl_stream::make_implementation(capy::any_stream& stream, tls_context const& ctx)
35 {
36 // Session creation is deferred to handshake time (the engine's
37 // prepare hook builds it lazily), so a session setup failure
38 // surfaces through the handshake completion instead of leaving a
39 // null implementation behind.
40
1/3
✓ Branch 4 → 5 taken 4191 times.
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
4191x return new implementation(stream, ctx);
41 }
42
43 4193x openssl_stream::~openssl_stream()
44 {
45
2/2
✓ Branch 2 → 3 taken 4190 times.
✓ Branch 2 → 5 taken 3 times.
4193x delete impl_;
46 4193x }
47
48 2x openssl_stream::openssl_stream(openssl_stream&& other) noexcept
49 2x : stream_(std::move(other.stream_))
50 2x , impl_(other.impl_)
51 {
52 2x other.impl_ = nullptr;
53
1/2
✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 7 not taken.
2x if (impl_)
54 2x impl_->rebind_stream(stream_);
55 2x }
56
57 openssl_stream&
58 1x openssl_stream::operator=(openssl_stream&& other) noexcept
59 {
60
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 10 not taken.
1x if (this != &other)
61 {
62
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 6 not taken.
1x delete impl_;
63 1x stream_ = std::move(other.stream_);
64 1x impl_ = other.impl_;
65 1x other.impl_ = nullptr;
66
1/2
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 10 not taken.
1x if (impl_)
67 1x impl_->rebind_stream(stream_);
68 }
69 1x return *this;
70 }
71
72 capy::io_task<std::size_t>
73
1/1
✓ Branch 6 → 7 taken 46539 times.
46539x openssl_stream::do_read_some(
74 capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers)
75 {
76 co_return co_await impl_->do_read_some(buffers);
77 93078x }
78
79 capy::io_task<std::size_t>
80
1/1
✓ Branch 6 → 7 taken 46425 times.
46425x openssl_stream::do_write_some(
81 capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers)
82 {
83 co_return co_await impl_->do_write_some(buffers);
84 92850x }
85
86 capy::io_task<>
87
1/1
✓ Branch 5 → 6 taken 2934 times.
2934x openssl_stream::handshake(tls_role role)
88 {
89 co_return co_await impl_->do_handshake(role);
90 5868x }
91
92 capy::io_task<>
93
1/1
✓ Branch 5 → 6 taken 145 times.
145x openssl_stream::shutdown()
94 {
95 co_return co_await impl_->do_shutdown();
96 290x }
97
98 void
99 60x openssl_stream::reset()
100 {
101 60x impl_->reset();
102 60x }
103
104 void
105 13x openssl_stream::set_hostname(std::string_view hostname)
106 {
107 13x impl_->set_hostname(hostname);
108 13x }
109
110 std::string_view
111 1x openssl_stream::name() const noexcept
112 {
113 1x return "openssl";
114 }
115
116 std::string_view
117 3x openssl_stream::alpn_protocol() const noexcept
118 {
119 3x return impl_->alpn_protocol();
120 }
121
122 } // namespace boost::corosio
123