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
4182x
100.0%
–
100.0%
boost::corosio::openssl_stream::implementation::implementation(boost::capy::any_stream&, boost::corosio::tls_context)
:30
4182x
100.0%
–
100.0%
boost::corosio::openssl_stream::make_implementation(boost::capy::any_stream&, boost::corosio::tls_context const&)
:34
2091x
66.7%
25.0%
33.0%
boost::corosio::openssl_stream::~openssl_stream()
:44
4194x
100.0%
100.0%
100.0%
boost::corosio::openssl_stream::openssl_stream(boost::corosio::openssl_stream&&)
:49
12x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::operator=(boost::corosio::openssl_stream&&)
:59
1x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::do_read_some(boost::capy::detail::buffer_array<16ul, false>)
:74
39806x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::do_write_some(boost::capy::detail::buffer_array<16ul, true>)
:81
39766x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::handshake(boost::corosio::tls_role)
:88
1614x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::shutdown()
:94
135x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::reset()
:100
60x
100.0%
–
100.0%
boost::corosio::openssl_stream::set_hostname(std::__1::basic_string_view<char, std::__1::char_traits<char>>)
:106
15x
100.0%
–
100.0%
boost::corosio::openssl_stream::name() const
:112
1x
100.0%
50.0%
66.0%
boost::corosio::openssl_stream::alpn_protocol() const
:118
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 | 2091x | 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/4✓ Branch 0 taken 2091 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2091x | return new implementation(stream, ctx); | |
| 42 | ✗ | } | ||
| 43 | ||||
| 44 | 4194x | openssl_stream::~openssl_stream() | ||
| 45 | 2097x | { | ||
| 46 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2090 times.
|
2097x | delete impl_; | |
| 47 | 4194x | } | ||
| 48 | ||||
| 49 | 12x | openssl_stream::openssl_stream(openssl_stream&& other) noexcept | ||
| 50 | 6x | : stream_(std::move(other.stream_)) | ||
| 51 | 6x | , impl_(other.impl_) | ||
| 52 | 12x | { | ||
| 53 | 6x | other.impl_ = nullptr; | ||
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6x | if (impl_) | |
| 55 | 6x | impl_->rebind_stream(stream_); | ||
| 56 | 12x | } | ||
| 57 | ||||
| 58 | openssl_stream& | |||
| 59 | 1x | openssl_stream::operator=(openssl_stream&& other) noexcept | ||
| 60 | { | |||
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | if (this != &other) | |
| 62 | { | |||
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | delete impl_; | |
| 64 | 1x | stream_ = std::move(other.stream_); | ||
| 65 | 1x | impl_ = other.impl_; | ||
| 66 | 1x | other.impl_ = nullptr; | ||
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | if (impl_) | |
| 68 | 1x | impl_->rebind_stream(stream_); | ||
| 69 | 1x | } | ||
| 70 | 1x | return *this; | ||
| 71 | } | |||
| 72 | ||||
| 73 | capy::io_task<std::size_t> | |||
| 74 |
11/24✓ Branch 0 taken 39806 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39806 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39806 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 79612 times.
✓ Branch 7 taken 119418 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 39806 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 39806 times.
✓ Branch 15 taken 39806 times.
✓ Branch 16 taken 39806 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 79612 times.
✓ Branch 19 taken 39806 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
278642x | openssl_stream::do_read_some( | |
| 75 | capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 76 | 39806x | { | ||
| 77 |
9/16✓ Branch 0 taken 119418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 119418 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39806 times.
✓ Branch 5 taken 79612 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 39806 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 39806 times.
✓ Branch 11 taken 39806 times.
✓ Branch 12 taken 39806 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 39806 times.
|
199030x | co_return co_await impl_->do_read_some(buffers); | |
| 78 | 79612x | } | ||
| 79 | ||||
| 80 | capy::io_task<std::size_t> | |||
| 81 |
11/24✓ Branch 0 taken 39766 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39766 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39766 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 79532 times.
✓ Branch 7 taken 119298 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 39766 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 39766 times.
✓ Branch 15 taken 39766 times.
✓ Branch 16 taken 39766 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 79532 times.
✓ Branch 19 taken 39766 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
278362x | openssl_stream::do_write_some( | |
| 82 | capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 83 | 39766x | { | ||
| 84 |
9/16✓ Branch 0 taken 119298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 119298 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39766 times.
✓ Branch 5 taken 79532 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 39766 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 39766 times.
✓ Branch 11 taken 39766 times.
✓ Branch 12 taken 39766 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 39766 times.
|
198830x | co_return co_await impl_->do_write_some(buffers); | |
| 85 | 79532x | } | ||
| 86 | ||||
| 87 | capy::io_task<> | |||
| 88 |
11/24✓ Branch 0 taken 1614 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1614 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1614 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3228 times.
✓ Branch 7 taken 4842 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1614 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1614 times.
✓ Branch 15 taken 1614 times.
✓ Branch 16 taken 1614 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 3228 times.
✓ Branch 19 taken 1614 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
11298x | openssl_stream::handshake(tls_role role) | |
| 89 | 1614x | { | ||
| 90 |
9/16✓ Branch 0 taken 4842 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4842 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1614 times.
✓ Branch 5 taken 3228 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1614 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1614 times.
✓ Branch 11 taken 1614 times.
✓ Branch 12 taken 1614 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1614 times.
|
8070x | co_return co_await impl_->do_handshake(role); | |
| 91 | 3228x | } | ||
| 92 | ||||
| 93 | capy::io_task<> | |||
| 94 |
11/24✓ Branch 0 taken 135 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 135 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 270 times.
✓ Branch 7 taken 405 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 135 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 135 times.
✓ Branch 15 taken 135 times.
✓ Branch 16 taken 135 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 270 times.
✓ Branch 19 taken 135 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
945x | openssl_stream::shutdown() | |
| 95 | 135x | { | ||
| 96 |
9/16✓ Branch 0 taken 405 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 405 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 135 times.
✓ Branch 5 taken 270 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 135 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 135 times.
✓ Branch 11 taken 135 times.
✓ Branch 12 taken 135 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 135 times.
|
540x | co_return co_await impl_->do_shutdown(); | |
| 97 | 270x | } | ||
| 98 | ||||
| 99 | void | |||
| 100 | 60x | openssl_stream::reset() | ||
| 101 | { | |||
| 102 | 60x | impl_->reset(); | ||
| 103 | 60x | } | ||
| 104 | ||||
| 105 | void | |||
| 106 | 15x | openssl_stream::set_hostname(std::string_view hostname) | ||
| 107 | { | |||
| 108 | 15x | impl_->set_hostname(hostname); | ||
| 109 | 15x | } | ||
| 110 | ||||
| 111 | std::string_view | |||
| 112 | 1x | openssl_stream::name() const noexcept | ||
| 113 | { | |||
| 114 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
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 |