src/openssl/src/openssl_stream.cpp
98.0% Lines (50/51)
100.0% List of functions (14/14)
50.0% Branches (88/176)
Functions (14)
Function
Calls
Lines
Branches
Blocks
boost::corosio::openssl_stream::implementation::~implementation()
:27
6142x
100.0%
–
100.0%
boost::corosio::openssl_stream::implementation::implementation(boost::capy::any_stream&, boost::corosio::tls_context)
:30
6142x
100.0%
–
100.0%
boost::corosio::openssl_stream::make_implementation(boost::capy::any_stream&, boost::corosio::tls_context const&)
:34
3071x
66.7%
25.0%
33.0%
boost::corosio::openssl_stream::~openssl_stream()
:43
6154x
100.0%
100.0%
100.0%
boost::corosio::openssl_stream::openssl_stream(boost::corosio::openssl_stream&&)
:48
12x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::operator=(boost::corosio::openssl_stream&&)
:58
1x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::do_read_some(boost::capy::detail::buffer_array<16ul, false>)
:73
143113x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::do_write_some(boost::capy::detail::buffer_array<16ul, true>)
:80
143061x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::handshake(boost::corosio::tls_role)
:87
2286x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::shutdown()
:93
133x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::reset()
:99
60x
100.0%
–
100.0%
boost::corosio::openssl_stream::set_hostname(std::__1::basic_string_view<char, std::__1::char_traits<char>>)
:105
13x
100.0%
–
100.0%
boost::corosio::openssl_stream::name() const
:111
1x
100.0%
50.0%
66.0%
boost::corosio::openssl_stream::alpn_protocol() const
:117
3x
100.0%
–
100.0%
| 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 | 3071x | 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/4✓ Branch 0 taken 3071 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
3071x | return new implementation(stream, ctx); | |
| 41 | ✗ | } | ||
| 42 | ||||
| 43 | 6154x | openssl_stream::~openssl_stream() | ||
| 44 | 3077x | { | ||
| 45 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3070 times.
|
3077x | delete impl_; | |
| 46 | 6154x | } | ||
| 47 | ||||
| 48 | 12x | openssl_stream::openssl_stream(openssl_stream&& other) noexcept | ||
| 49 | 6x | : stream_(std::move(other.stream_)) | ||
| 50 | 6x | , impl_(other.impl_) | ||
| 51 | 12x | { | ||
| 52 | 6x | other.impl_ = nullptr; | ||
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6x | if (impl_) | |
| 54 | 6x | impl_->rebind_stream(stream_); | ||
| 55 | 12x | } | ||
| 56 | ||||
| 57 | openssl_stream& | |||
| 58 | 1x | openssl_stream::operator=(openssl_stream&& other) noexcept | ||
| 59 | { | |||
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | if (this != &other) | |
| 61 | { | |||
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | delete impl_; | |
| 63 | 1x | stream_ = std::move(other.stream_); | ||
| 64 | 1x | impl_ = other.impl_; | ||
| 65 | 1x | other.impl_ = nullptr; | ||
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | if (impl_) | |
| 67 | 1x | impl_->rebind_stream(stream_); | ||
| 68 | 1x | } | ||
| 69 | 1x | return *this; | ||
| 70 | } | |||
| 71 | ||||
| 72 | capy::io_task<std::size_t> | |||
| 73 |
11/24✓ Branch 0 taken 143113 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 143113 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 143113 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 286226 times.
✓ Branch 7 taken 429339 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 143113 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 143113 times.
✓ Branch 15 taken 143113 times.
✓ Branch 16 taken 143113 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 286226 times.
✓ Branch 19 taken 143113 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1001791x | openssl_stream::do_read_some( | |
| 74 | capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 75 | 143113x | { | ||
| 76 |
9/16✓ Branch 0 taken 429339 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429339 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 143113 times.
✓ Branch 5 taken 286226 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 143113 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 143113 times.
✓ Branch 11 taken 143113 times.
✓ Branch 12 taken 143113 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 143113 times.
|
715565x | co_return co_await impl_->do_read_some(buffers); | |
| 77 | 286226x | } | ||
| 78 | ||||
| 79 | capy::io_task<std::size_t> | |||
| 80 |
11/24✓ Branch 0 taken 143061 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 143061 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 143061 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 286122 times.
✓ Branch 7 taken 429183 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 143061 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 143061 times.
✓ Branch 15 taken 143061 times.
✓ Branch 16 taken 143061 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 286122 times.
✓ Branch 19 taken 143061 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1001427x | openssl_stream::do_write_some( | |
| 81 | capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 82 | 143061x | { | ||
| 83 |
9/16✓ Branch 0 taken 429183 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429183 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 143061 times.
✓ Branch 5 taken 286122 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 143061 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 143061 times.
✓ Branch 11 taken 143061 times.
✓ Branch 12 taken 143061 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 143061 times.
|
715305x | co_return co_await impl_->do_write_some(buffers); | |
| 84 | 286122x | } | ||
| 85 | ||||
| 86 | capy::io_task<> | |||
| 87 |
11/24✓ Branch 0 taken 2286 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2286 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2286 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4572 times.
✓ Branch 7 taken 6858 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 2286 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 2286 times.
✓ Branch 15 taken 2286 times.
✓ Branch 16 taken 2286 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4572 times.
✓ Branch 19 taken 2286 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
16002x | openssl_stream::handshake(tls_role role) | |
| 88 | 2286x | { | ||
| 89 |
9/16✓ Branch 0 taken 6858 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6858 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2286 times.
✓ Branch 5 taken 4572 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2286 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 2286 times.
✓ Branch 11 taken 2286 times.
✓ Branch 12 taken 2286 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 2286 times.
|
11430x | co_return co_await impl_->do_handshake(role); | |
| 90 | 4572x | } | ||
| 91 | ||||
| 92 | capy::io_task<> | |||
| 93 |
11/24✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 133 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 133 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 266 times.
✓ Branch 7 taken 399 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 133 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 133 times.
✓ Branch 15 taken 133 times.
✓ Branch 16 taken 133 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 266 times.
✓ Branch 19 taken 133 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
931x | openssl_stream::shutdown() | |
| 94 | 133x | { | ||
| 95 |
9/16✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 133 times.
✓ Branch 5 taken 266 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 133 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 133 times.
✓ Branch 11 taken 133 times.
✓ Branch 12 taken 133 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 133 times.
|
532x | co_return co_await impl_->do_shutdown(); | |
| 96 | 266x | } | ||
| 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 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
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 |