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