src/openssl/src/openssl_stream.cpp
96.4% Lines (54/56)
100.0% List of functions (14/14)
49.4% Branches (89/180)
Functions (14)
Function
Calls
Lines
Branches
Blocks
boost::corosio::openssl_stream::implementation::~implementation()
:27
5564x
100.0%
–
100.0%
boost::corosio::openssl_stream::implementation::implementation(boost::capy::any_stream&, boost::corosio::tls_context)
:30
5564x
100.0%
–
100.0%
boost::corosio::openssl_stream::make_implementation(boost::capy::any_stream&, boost::corosio::tls_context const&)
:34
2782x
75.0%
25.0%
36.0%
boost::corosio::openssl_stream::~openssl_stream()
:48
5576x
100.0%
100.0%
100.0%
boost::corosio::openssl_stream::openssl_stream(boost::corosio::openssl_stream&&)
:53
12x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::operator=(boost::corosio::openssl_stream&&)
:63
1x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::do_read_some(boost::capy::detail::buffer_array<16ul, false>)
:78
139700x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::do_write_some(boost::capy::detail::buffer_array<16ul, true>)
:85
139668x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::handshake(boost::corosio::tls_role)
:92
2130x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::shutdown()
:98
132x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::reset()
:104
60x
100.0%
–
100.0%
boost::corosio::openssl_stream::set_hostname(std::__1::basic_string_view<char, std::__1::char_traits<char>>)
:110
13x
100.0%
–
100.0%
boost::corosio::openssl_stream::name() const
:116
1x
100.0%
50.0%
66.0%
boost::corosio::openssl_stream::alpn_protocol() const
:122
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 | 2782x | openssl_stream::make_implementation(capy::any_stream& stream, tls_context const& ctx) | ||
| 35 | { | |||
| 36 |
1/4✓ Branch 0 taken 2782 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2782x | auto* p = new implementation(stream, ctx); | |
| 37 | ||||
| 38 | 2782x | auto ec = p->engine().init(p->context()); | ||
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2782 times.
|
2782x | if (ec) | |
| 40 | { | |||
| 41 | ✗ | delete p; | ||
| 42 | ✗ | return nullptr; | ||
| 43 | } | |||
| 44 | ||||
| 45 | 2782x | return p; | ||
| 46 | 2782x | } | ||
| 47 | ||||
| 48 | 5576x | openssl_stream::~openssl_stream() | ||
| 49 | 2788x | { | ||
| 50 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2781 times.
|
2788x | delete impl_; | |
| 51 | 5576x | } | ||
| 52 | ||||
| 53 | 12x | openssl_stream::openssl_stream(openssl_stream&& other) noexcept | ||
| 54 | 6x | : stream_(std::move(other.stream_)) | ||
| 55 | 6x | , impl_(other.impl_) | ||
| 56 | 12x | { | ||
| 57 | 6x | other.impl_ = nullptr; | ||
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6x | if (impl_) | |
| 59 | 6x | impl_->rebind_stream(stream_); | ||
| 60 | 12x | } | ||
| 61 | ||||
| 62 | openssl_stream& | |||
| 63 | 1x | openssl_stream::operator=(openssl_stream&& other) noexcept | ||
| 64 | { | |||
| 65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | if (this != &other) | |
| 66 | { | |||
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | delete impl_; | |
| 68 | 1x | stream_ = std::move(other.stream_); | ||
| 69 | 1x | impl_ = other.impl_; | ||
| 70 | 1x | other.impl_ = nullptr; | ||
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | if (impl_) | |
| 72 | 1x | impl_->rebind_stream(stream_); | ||
| 73 | 1x | } | ||
| 74 | 1x | return *this; | ||
| 75 | } | |||
| 76 | ||||
| 77 | capy::io_task<std::size_t> | |||
| 78 |
11/24✓ Branch 0 taken 139700 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139700 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139700 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 279400 times.
✓ Branch 7 taken 419100 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 139700 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 139700 times.
✓ Branch 15 taken 139700 times.
✓ Branch 16 taken 139700 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 279400 times.
✓ Branch 19 taken 139700 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
977900x | openssl_stream::do_read_some( | |
| 79 | capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 80 | 139700x | { | ||
| 81 |
9/16✓ Branch 0 taken 419100 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 419100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139700 times.
✓ Branch 5 taken 279400 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 139700 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 139700 times.
✓ Branch 11 taken 139700 times.
✓ Branch 12 taken 139700 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 139700 times.
|
698500x | co_return co_await impl_->do_read_some(buffers); | |
| 82 | 279400x | } | ||
| 83 | ||||
| 84 | capy::io_task<std::size_t> | |||
| 85 |
11/24✓ Branch 0 taken 139668 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139668 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139668 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 279336 times.
✓ Branch 7 taken 419004 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 139668 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 139668 times.
✓ Branch 15 taken 139668 times.
✓ Branch 16 taken 139668 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 279336 times.
✓ Branch 19 taken 139668 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
977676x | openssl_stream::do_write_some( | |
| 86 | capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 87 | 139668x | { | ||
| 88 |
9/16✓ Branch 0 taken 419004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 419004 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139668 times.
✓ Branch 5 taken 279336 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 139668 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 139668 times.
✓ Branch 11 taken 139668 times.
✓ Branch 12 taken 139668 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 139668 times.
|
698340x | co_return co_await impl_->do_write_some(buffers); | |
| 89 | 279336x | } | ||
| 90 | ||||
| 91 | capy::io_task<> | |||
| 92 |
11/24✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2130 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4260 times.
✓ Branch 7 taken 6390 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 2130 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 2130 times.
✓ Branch 15 taken 2130 times.
✓ Branch 16 taken 2130 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4260 times.
✓ Branch 19 taken 2130 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
14910x | openssl_stream::handshake(tls_role role) | |
| 93 | 2130x | { | ||
| 94 |
9/16✓ Branch 0 taken 6390 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6390 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2130 times.
✓ Branch 5 taken 4260 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2130 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 2130 times.
✓ Branch 11 taken 2130 times.
✓ Branch 12 taken 2130 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 2130 times.
|
10650x | co_return co_await impl_->do_handshake(role); | |
| 95 | 4260x | } | ||
| 96 | ||||
| 97 | capy::io_task<> | |||
| 98 |
11/24✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 264 times.
✓ Branch 7 taken 396 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 132 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 132 times.
✓ Branch 15 taken 132 times.
✓ Branch 16 taken 132 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 264 times.
✓ Branch 19 taken 132 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
924x | openssl_stream::shutdown() | |
| 99 | 132x | { | ||
| 100 |
9/16✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 396 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 264 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 132 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 132 times.
✓ Branch 11 taken 132 times.
✓ Branch 12 taken 132 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 132 times.
|
528x | co_return co_await impl_->do_shutdown(); | |
| 101 | 264x | } | ||
| 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 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
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 |