CI: fixing the files to be complient with pre-commit hooks

This commit is contained in:
Suren Gabrielyan
2022-10-11 16:31:57 +02:00
parent 9d45d505d5
commit 945bd17701
205 changed files with 3130 additions and 3441 deletions

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//
@ -87,7 +87,7 @@ public:
return flags_ & BIO_FLAGS_READ;
}
static std::pair<std::shared_ptr<bio>, std::shared_ptr<bio>> new_pair(const char* error_location)
static std::pair<std::shared_ptr<bio>, std::shared_ptr<bio>> new_pair(const char *error_location)
{
auto b1 = std::shared_ptr<bio>(new (std::nothrow) bio);
auto b2 = std::shared_ptr<bio>(new (std::nothrow) bio);
@ -110,4 +110,6 @@ private:
size_t flags_ {0};
};
} } } // namespace asio::ssl::mbedtls
}
}
} // namespace asio::ssl::mbedtls

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//
@ -11,13 +11,13 @@
namespace asio {
namespace error {
const asio::error_category& get_mbedtls_category();
const asio::error_category &get_mbedtls_category();
} // namespace error
namespace ssl {
namespace mbedtls {
void throw_alloc_failure(const char* location);
void throw_alloc_failure(const char *location);
const char *error_message(int error_code);
@ -26,11 +26,10 @@ enum class container {
};
template <typename T, typename... Args>
inline T* create(const char * location, Args &&... args)
inline T *create(const char *location, Args &&... args)
{
T* t = new (std::nothrow) T(std::forward<Args>(args)...);
if (t == nullptr)
{
T *t = new (std::nothrow) T(std::forward<Args>(args)...);
if (t == nullptr) {
throw_alloc_failure(location);
}
return t;
@ -43,12 +42,12 @@ public:
const unsigned char *data(container c) const
{
switch (c) {
case container::CERT:
return static_cast<const unsigned char *>(cert_chain_.data());
case container::CA_CERT:
return static_cast<const unsigned char *>(ca_cert_.data());
case container::PRIVKEY:
return static_cast<const unsigned char *>(private_key_.data());
case container::CERT:
return static_cast<const unsigned char *>(cert_chain_.data());
case container::CA_CERT:
return static_cast<const unsigned char *>(ca_cert_.data());
case container::PRIVKEY:
return static_cast<const unsigned char *>(private_key_.data());
}
return nullptr;
}
@ -56,12 +55,12 @@ public:
std::size_t size(container c) const
{
switch (c) {
case container::CERT:
return cert_chain_.size();
case container::CA_CERT:
return ca_cert_.size();
case container::PRIVKEY:
return private_key_.size();
case container::CERT:
return cert_chain_.size();
case container::CA_CERT:
return ca_cert_.size();
case container::PRIVKEY:
return private_key_.size();
}
return 0;
}
@ -80,11 +79,10 @@ public:
*/
class shared_ctx {
public:
static SSL_CTX *create(const char* location, context_base::method m)
static SSL_CTX *create(const char *location, context_base::method m)
{
auto wrapped = asio::ssl::mbedtls::create<shared_ctx>(location, m);
if (wrapped->ctx_ == nullptr)
{
if (wrapped->ctx_ == nullptr) {
throw_alloc_failure(location);
}
return wrapped;
@ -96,10 +94,12 @@ public:
}
explicit shared_ctx(context_base::method m)
:ctx_(std::shared_ptr<context>(new (std::nothrow) context(m))) { }
: ctx_(std::shared_ptr<context>(new (std::nothrow) context(m))) { }
private:
std::shared_ptr<mbedtls::context> ctx_;
};
} } } // namespace asio::ssl::mbedtls
}
}
} // namespace asio::ssl::mbedtls

View File

@ -23,7 +23,7 @@ const char *error_message(int error_code)
return error_buf;
}
void throw_alloc_failure(const char* location)
void throw_alloc_failure(const char *location)
{
asio::error_code ec( MBEDTLS_ERR_SSL_ALLOC_FAILED, asio::error::get_mbedtls_category());
asio::detail::throw_error(ec, location);
@ -62,7 +62,7 @@ public:
verify_mode_ = mode;
}
bio* ext_bio() const
bio *ext_bio() const
{
return bio_.second.get();
}
@ -95,14 +95,14 @@ public:
int write(const void *buffer, int len)
{
int ret = impl_.write(buffer, len);
state_ = ret == len ? IDLE: WRITING;
state_ = ret == len ? IDLE : WRITING;
return ret;
}
int read(void *buffer, int len)
{
int ret = impl_.read(buffer, len);
state_ = ret == len ? IDLE: READING;
state_ = ret == len ? IDLE : READING;
return ret;
}
@ -117,7 +117,7 @@ private:
static int bio_read(void *ctx, unsigned char *buf, size_t len)
{
auto bio = static_cast<BIO*>(ctx);
auto bio = static_cast<BIO *>(ctx);
int read = bio->read(buf, len);
if (read <= 0 && bio->should_read()) {
return MBEDTLS_ERR_SSL_WANT_READ;
@ -127,7 +127,7 @@ private:
static int bio_write(void *ctx, const unsigned char *buf, size_t len)
{
auto bio = static_cast<BIO*>(ctx);
auto bio = static_cast<BIO *>(ctx);
int written = bio->write(buf, len);
if (written <= 0 && bio->should_write()) {
return MBEDTLS_ERR_SSL_WANT_WRITE;
@ -163,25 +163,27 @@ private:
{
int mode = MBEDTLS_SSL_VERIFY_UNSET;
if (is_client_not_server) {
if (verify_mode_ & SSL_VERIFY_PEER)
if (verify_mode_ & SSL_VERIFY_PEER) {
mode = MBEDTLS_SSL_VERIFY_REQUIRED;
else if (verify_mode_ == SSL_VERIFY_NONE)
} else if (verify_mode_ == SSL_VERIFY_NONE) {
mode = MBEDTLS_SSL_VERIFY_NONE;
}
} else {
if (verify_mode_ & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
if (verify_mode_ & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
mode = MBEDTLS_SSL_VERIFY_REQUIRED;
else if (verify_mode_ & SSL_VERIFY_PEER)
} else if (verify_mode_ & SSL_VERIFY_PEER) {
mode = MBEDTLS_SSL_VERIFY_OPTIONAL;
else if (verify_mode_ == SSL_VERIFY_NONE)
} else if (verify_mode_ == SSL_VERIFY_NONE) {
mode = MBEDTLS_SSL_VERIFY_NONE;
}
}
return mode;
}
struct impl {
static void print_error(const char* function, int error_code)
static void print_error(const char *function, int error_code)
{
constexpr const char *TAG="mbedtls-engine-impl";
constexpr const char *TAG = "mbedtls-engine-impl";
ESP_LOGE(TAG, "%s() returned -0x%04X", function, -error_code);
ESP_LOGI(TAG, "-0x%04X: %s", -error_code, error_message(error_code));
}
@ -230,7 +232,7 @@ private:
mbedtls_x509_crt_init(&public_cert_);
mbedtls_pk_init(&pk_key_);
mbedtls_x509_crt_init(&ca_cert_);
int ret = mbedtls_ssl_config_defaults(&conf_, is_client_not_server ? MBEDTLS_SSL_IS_CLIENT: MBEDTLS_SSL_IS_SERVER,
int ret = mbedtls_ssl_config_defaults(&conf_, is_client_not_server ? MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
if (ret) {
print_error("mbedtls_ssl_config_defaults", ret);
@ -290,4 +292,6 @@ private:
asio::ssl::verify_mode verify_mode_;
};
} } } // namespace asio::ssl::mbedtls
}
}
} // namespace asio::ssl::mbedtls

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//
@ -14,30 +14,29 @@ namespace asio {
namespace error {
namespace detail {
class mbedtls_category : public asio::error_category
{
class mbedtls_category : public asio::error_category {
public:
const char* name() const ASIO_ERROR_CATEGORY_NOEXCEPT
const char *name() const ASIO_ERROR_CATEGORY_NOEXCEPT
{
return "asio.ssl";
}
std::string message(int value) const
{
const char* s = asio::ssl::mbedtls::error_message(value);
const char *s = asio::ssl::mbedtls::error_message(value);
return s ? s : "asio.mbedtls error";
}
};
} // namespace detail
const asio::error_category& get_mbedtls_category()
const asio::error_category &get_mbedtls_category()
{
static detail::mbedtls_category instance;
return instance;
}
const asio::error_category& get_ssl_category()
const asio::error_category &get_ssl_category()
{
return asio::error::get_mbedtls_category();
}
@ -47,9 +46,11 @@ const asio::error_category& get_ssl_category()
namespace ssl {
namespace error {
const asio::error_category& get_stream_category()
const asio::error_category &get_stream_category()
{
return asio::error::get_mbedtls_category();
}
} } } // namespace asio::ssl::error
}
}
} // namespace asio::ssl::error

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//

View File

@ -1,5 +1,5 @@
//
// SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
// SPDX-License-Identifier: BSL-1.0
//

View File

@ -4,7 +4,7 @@
//
// SPDX-License-Identifier: BSL-1.0
//
// SPDX-FileContributor: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileContributor: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
#include "asio/detail/config.hpp"
@ -22,19 +22,19 @@ namespace ssl {
context::context(context::method m)
: handle_(0)
: handle_(0)
{
handle_ = mbedtls::shared_ctx::create("mbedtls-context", m);
set_options(no_compression);
}
context::context(context&& other)
context::context(context &&other)
{
handle_ = other.handle_;
other.handle_ = 0;
}
context& context::operator=(context&& other)
context &context::operator=(context &&other)
{
context tmp(ASIO_MOVE_CAST(context)(*this));
handle_ = other.handle_;
@ -60,14 +60,14 @@ void context::set_options(context::options o)
}
ASIO_SYNC_OP_VOID context::set_options(
context::options o, asio::error_code& ec)
context::options o, asio::error_code &ec)
{
handle_->get()->options_ = o;
ec = asio::error_code();
ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::add_certificate_authority(const const_buffer& ca)
void context::add_certificate_authority(const const_buffer &ca)
{
asio::error_code ec;
add_certificate_authority(ca, ec);
@ -75,13 +75,13 @@ void context::add_certificate_authority(const const_buffer& ca)
}
ASIO_SYNC_OP_VOID context::add_certificate_authority(
const const_buffer& ca, asio::error_code& ec)
const const_buffer &ca, asio::error_code &ec)
{
handle_->get()->ca_cert_ = ca;
ASIO_SYNC_OP_VOID_RETURN(asio::error_code());
}
void context::use_certificate_chain(const const_buffer& chain)
void context::use_certificate_chain(const const_buffer &chain)
{
asio::error_code ec;
use_certificate_chain(chain, ec);
@ -89,14 +89,14 @@ void context::use_certificate_chain(const const_buffer& chain)
}
ASIO_SYNC_OP_VOID context::use_certificate_chain(
const const_buffer& chain, asio::error_code& ec)
const const_buffer &chain, asio::error_code &ec)
{
handle_->get()->cert_chain_ = chain;
ASIO_SYNC_OP_VOID_RETURN(asio::error_code());
}
void context::use_private_key(
const const_buffer& private_key, context::file_format format)
const const_buffer &private_key, context::file_format format)
{
asio::error_code ec;
use_private_key(private_key, format, ec);
@ -104,8 +104,8 @@ void context::use_private_key(
}
ASIO_SYNC_OP_VOID context::use_private_key(
const const_buffer& private_key, context::file_format format,
asio::error_code& ec)
const const_buffer &private_key, context::file_format format,
asio::error_code &ec)
{
handle_->get()->private_key_ = private_key;
ASIO_SYNC_OP_VOID_RETURN(asio::error_code());

View File

@ -3,7 +3,7 @@
//
// SPDX-License-Identifier: BSL-1.0
//
// SPDX-FileContributor: 2021 Espressif Systems (Shanghai) CO LTD
// SPDX-FileContributor: 2021-2022 Espressif Systems (Shanghai) CO LTD
//
#include "asio/detail/config.hpp"
@ -24,8 +24,8 @@ namespace ssl {
namespace detail {
engine::engine(SSL_CTX* context)
: ssl_(nullptr)
engine::engine(SSL_CTX *context)
: ssl_(nullptr)
{
ssl_ = mbedtls::create<mbedtls::engine>("mbedtls-engine", context->get());
}
@ -35,49 +35,47 @@ engine::~engine()
delete ssl_;
}
SSL* engine::native_handle()
SSL *engine::native_handle()
{
return ssl_;
}
asio::error_code engine::set_verify_mode(
verify_mode v, asio::error_code& ec)
verify_mode v, asio::error_code &ec)
{
ssl_->set_verify_mode(v);
return {};
}
engine::want engine::handshake(
stream_base::handshake_type type, asio::error_code& ec)
stream_base::handshake_type type, asio::error_code &ec)
{
return perform((type == asio::ssl::stream_base::client)
? &engine::do_connect : &engine::do_accept, 0, 0, ec, 0);
}
engine::want engine::shutdown(asio::error_code& ec)
engine::want engine::shutdown(asio::error_code &ec)
{
return perform(&engine::do_shutdown, 0, 0, ec, 0);
}
engine::want engine::write(const asio::const_buffer& data,
asio::error_code& ec, std::size_t& bytes_transferred)
engine::want engine::write(const asio::const_buffer &data,
asio::error_code &ec, std::size_t &bytes_transferred)
{
if (data.size() == 0)
{
if (data.size() == 0) {
ec = asio::error_code();
return engine::want_nothing;
}
return perform(&engine::do_write,
const_cast<void*>(data.data()),
const_cast<void *>(data.data()),
data.size(), ec, &bytes_transferred);
}
engine::want engine::read(const asio::mutable_buffer& data,
asio::error_code& ec, std::size_t& bytes_transferred)
engine::want engine::read(const asio::mutable_buffer &data,
asio::error_code &ec, std::size_t &bytes_transferred)
{
if (data.size() == 0)
{
if (data.size() == 0) {
ec = asio::error_code();
return engine::want_nothing;
}
@ -87,7 +85,7 @@ engine::want engine::read(const asio::mutable_buffer& data,
}
asio::mutable_buffer engine::get_output(
const asio::mutable_buffer& data)
const asio::mutable_buffer &data)
{
int length = ssl_->ext_bio()->read(data.data(), static_cast<int>(data.size()));
@ -96,7 +94,7 @@ asio::mutable_buffer engine::get_output(
}
asio::const_buffer engine::put_input(
const asio::const_buffer& data)
const asio::const_buffer &data)
{
int length = ssl_->ext_bio()->write(data.data(), static_cast<int>(data.size()));
@ -104,23 +102,22 @@ asio::const_buffer engine::put_input(
(length > 0 ? static_cast<std::size_t>(length) : 0));
}
const asio::error_code& engine::map_error_code(
asio::error_code& ec) const
const asio::error_code &engine::map_error_code(
asio::error_code &ec) const
{
// We only want to map the error::eof code.
if (ec != asio::error::eof)
if (ec != asio::error::eof) {
return ec;
}
// If there's data yet to be read, it's an error.
if (ssl_->ext_bio()->wpending())
{
if (ssl_->ext_bio()->wpending()) {
ec = asio::ssl::error::stream_truncated;
return ec;
}
// Otherwise, the peer should have negotiated a proper shutdown.
if (ssl_->shutdown() != 0)
{
if (ssl_->shutdown() != 0) {
ec = asio::ssl::error::stream_truncated;
}
@ -129,47 +126,39 @@ const asio::error_code& engine::map_error_code(
// This is a simplified implementation of a generic ssl io operation
// original implementation using openssl's SSL object is in asio/include/asio/ssl/detail/impl/engine.ipp
engine::want engine::perform(int (engine::* op)(void*, std::size_t),
void* data, std::size_t length, asio::error_code& ec,
std::size_t* bytes_transferred)
engine::want engine::perform(int (engine::* op)(void *, std::size_t),
void *data, std::size_t length, asio::error_code &ec,
std::size_t *bytes_transferred)
{
std::size_t pending_output_before = ssl_->ext_bio()->ctrl_pending();
int result = (this->*op)(data, length);
std::size_t pending_output_after = ssl_->ext_bio()->ctrl_pending();
if (mbedtls::error_codes::is_error(result))
{
if (mbedtls::error_codes::is_error(result)) {
ec = asio::error_code(result, asio::error::get_mbedtls_category());
return pending_output_after > pending_output_before ? want_output : want_nothing;
}
if (result == 0)
{
if (result == 0) {
return pending_output_after > pending_output_before
? want_output : want_nothing;
}
if (result > 0 && bytes_transferred)
if (result > 0 && bytes_transferred) {
*bytes_transferred = static_cast<std::size_t>(result);
}
if (mbedtls::error_codes::want_write(result))
{
if (mbedtls::error_codes::want_write(result)) {
ec = asio::error_code();
return want_output_and_retry;
}
else if (pending_output_after > pending_output_before)
{
} else if (pending_output_after > pending_output_before) {
ec = asio::error_code();
return result > 0 ? want_output : want_output_and_retry;
}
else if (mbedtls::error_codes::want_read(result))
{
} else if (mbedtls::error_codes::want_read(result)) {
ec = asio::error_code();
return want_input_and_retry;
}
else if (ssl_->get_state() == mbedtls::CLOSED)
{
} else if (ssl_->get_state() == mbedtls::CLOSED) {
ec = asio::error::eof;
return want_nothing;
}
@ -178,27 +167,27 @@ engine::want engine::perform(int (engine::* op)(void*, std::size_t),
return want_nothing;
}
int engine::do_accept(void*, std::size_t)
int engine::do_accept(void *, std::size_t)
{
return ssl_->accept();
}
int engine::do_connect(void*, std::size_t)
int engine::do_connect(void *, std::size_t)
{
return ssl_->connect();
}
int engine::do_shutdown(void*, std::size_t)
int engine::do_shutdown(void *, std::size_t)
{
return ssl_->shutdown();
}
int engine::do_read(void* data, std::size_t length)
int engine::do_read(void *data, std::size_t length)
{
return ssl_->read(data, length < INT_MAX ? static_cast<int>(length) : INT_MAX);
}
int engine::do_write(void* data, std::size_t length)
int engine::do_write(void *data, std::size_t length)
{
return ssl_->write(data, length < INT_MAX ? static_cast<int>(length) : INT_MAX);
}