Renamed 'trust_store' to 'trust_locations' and ran format over sources.

This commit is contained in:
fpagliughi
2025-01-16 18:02:52 -05:00
parent 3d99bd7036
commit e227f81f32
13 changed files with 58 additions and 52 deletions

View File

@@ -54,7 +54,7 @@ int main(int argc, char* argv[]) {
in_port_t port = (argc > 2) ? atoi(argv[2]) : 443;
string trustStore = (argc > 3) ? argv[3] : "";
const string REQUEST = string{"GET / HTTP/1.1\r\nHost: "} + host + "\r\n\r\n";
const string REQUEST = string{"GET / HTTP/1.0\r\nHost: "} + host + "\r\n\r\n";
sockpp::initialize();
@@ -66,12 +66,11 @@ int main(int argc, char* argv[]) {
auto ctx = sockpp::tls_context_builder::client().verify_peer().finalize();
if (trustStore.empty())
ctx.set_default_trust_store();
ctx.set_default_trust_locations();
else
ctx.set_trust_file(trustStore);
// Implicitly creates an inet_address from {host,port}
// and then tries the connection.
// Creates an inet_address from {host,port} and then try the connection.
error_code ec;

View File

@@ -102,7 +102,7 @@ int main(int argc, char* argv[]) {
ctxBldr.verify_peer();
if (trustStore.empty())
ctxBldr.default_trust_store();
ctxBldr.default_trust_locations();
else
ctxBldr.trust_file(trustStore);

View File

@@ -50,11 +50,11 @@ int main(int argc, char* argv[]) {
cout << "Sample Unix-domain echo client for 'sockpp' " << sockpp::SOCKPP_VERSION << '\n'
<< endl;
#if defined(_WIN32)
const string DFLT_PATH = "C:\\TEMP\\unechosvr.sock"s;
#else
string DFLT_PATH = "/tmp/unechosvr.sock"s;
#endif
#if defined(_WIN32)
const string DFLT_PATH = "C:\\TEMP\\unechosvr.sock"s;
#else
string DFLT_PATH = "/tmp/unechosvr.sock"s;
#endif
const string path = (argc > 1) ? argv[1] : DFLT_PATH;

View File

@@ -40,12 +40,12 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// --------------------------------------------------------------------------
#include "sockpp/unix_acceptor.h"
#include "sockpp/version.h"
#include <iostream>
#include <thread>
#include "sockpp/unix_acceptor.h"
#include "sockpp/version.h"
using namespace std;
// --------------------------------------------------------------------------
@@ -72,12 +72,11 @@ int main(int argc, char* argv[]) {
cout << "Sample Unix-domain echo server for 'sockpp' " << sockpp::SOCKPP_VERSION << '\n'
<< endl;
#if defined(_WIN32)
const string DFLT_PATH = "C:\\TEMP\\unechosvr.sock"s;
#else
string DFLT_PATH = "/tmp/unechosvr.sock"s;
#endif
#if defined(_WIN32)
const string DFLT_PATH = "C:\\TEMP\\unechosvr.sock"s;
#else
string DFLT_PATH = "/tmp/unechosvr.sock"s;
#endif
const string path = (argc > 1) ? argv[1] : DFLT_PATH;

View File

@@ -59,11 +59,11 @@ int main(int argc, char* argv[]) {
<< '\n'
<< endl;
#if defined(_WIN32)
const string DFLT_PATH = "C:\\TEMP\\unechosvr.sock"s;
#else
string DFLT_PATH = "/tmp/unechosvr.sock"s;
#endif
#if defined(_WIN32)
const string DFLT_PATH = "C:\\TEMP\\unechosvr.sock"s;
#else
string DFLT_PATH = "/tmp/unechosvr.sock"s;
#endif
const string path = (argc > 1) ? argv[1] : DFLT_PATH;
size_t n = (argc > 2) ? size_t(atoll(argv[2])) : DFLT_N;

View File

@@ -416,8 +416,9 @@ public:
* @return bool @em true if the value was retrieved, @em false if an error
* occurred.
*/
result<> get_option(int level, int optname, void* optval, socklen_t* optlen)
const noexcept;
result<> get_option(
int level, int optname, void* optval, socklen_t* optlen
) const noexcept;
/**
* Gets the value of a socket option.
*

View File

@@ -110,9 +110,9 @@ public:
* Specify that application should use the default locations of the CA
* certificates as the trust store.
*/
auto default_trust_store() -> self& {
auto default_trust_locations() -> self& {
if (!ec_) {
if (auto res = ctx_.set_default_trust_store(); !res)
if (auto res = ctx_.set_default_trust_locations(); !res)
ec_ = res.error();
}
return *this;

View File

@@ -124,8 +124,9 @@ public:
*/
void set_identity(mbedtls_x509_crt* certificate, mbedtls_pk_context* private_key);
void set_identity(const string& certificate_data, const string& private_key_data)
override;
void set_identity(
const string& certificate_data, const string& private_key_data
) override;
std::unique_ptr<tls_socket> wrap_socket(
stream_socket&& sock, role_t role = UNKNOWN, const string& peer_name = string{}

View File

@@ -141,7 +141,7 @@ public:
* certificates.
* @return @em true on success, @em false on failure.
*/
result<> set_default_trust_store();
result<> set_default_trust_locations();
/**
* Sets a file of CA certificates as the trust store. The file should be
* in PEM format.
@@ -173,7 +173,7 @@ public:
* trust store.
* @return The error code on failure
*/
result<> set_trust_store(
result<> set_trust_locations(
const std::optional<string>& caFile,
const std::optional<string>& caPath = std::nullopt
);

View File

@@ -46,15 +46,15 @@
#ifndef __sockpp_unix_addr_h
#define __sockpp_unix_addr_h
#include <cstring>
#include <iostream>
#include <string>
#include "sockpp/platform.h"
#include "sockpp/result.h"
#include "sockpp/sock_address.h"
#include "sockpp/types.h"
#include <cstring>
#include <iostream>
#include <string>
#if defined(_WIN32)
#include <afunix.h>
#else

View File

@@ -261,15 +261,16 @@ sock_address_any socket::peer_address() const {
// --------------------------------------------------------------------------
result<> socket::get_option(int level, int optname, void* optval, socklen_t* optlen)
const noexcept {
result<> socket::get_option(
int level, int optname, void* optval, socklen_t* optlen
) const noexcept {
result<int> res;
#if defined(_WIN32)
if (optval && optlen) {
int len = static_cast<int>(*optlen);
res =
check_res(::getsockopt(handle_, level, optname, static_cast<char*>(optval), &len)
);
res = check_res(
::getsockopt(handle_, level, optname, static_cast<char*>(optval), &len)
);
if (res) {
*optlen = static_cast<socklen_t>(len);
}
@@ -286,9 +287,12 @@ result<> socket::set_option(
int level, int optname, const void* optval, socklen_t optlen
) noexcept {
#if defined(_WIN32)
return check_res_none(::setsockopt(
handle_, level, optname, static_cast<const char*>(optval), static_cast<int>(optlen)
));
return check_res_none(
::setsockopt(
handle_, level, optname, static_cast<const char*>(optval),
static_cast<int>(optlen)
)
);
#else
return check_res_none(::setsockopt(handle_, level, optname, optval, optlen));
#endif

View File

@@ -85,17 +85,19 @@ tls_context& tls_context::operator=(tls_context&& rhs) {
return *this;
}
result<> tls_context::set_default_trust_store() {
result<> tls_context::set_default_trust_locations() {
return tls_check_res_none(::SSL_CTX_set_default_verify_paths(ctx_));
}
result<> tls_context::set_trust_store(
result<> tls_context::set_trust_locations(
const std::optional<string>& caFile, const std::optional<string>& caPath /*=std::nullopt*/
) {
return tls_check_res_none(::SSL_CTX_load_verify_locations(
ctx_, caFile ? caFile.value().c_str() : nullptr,
caPath ? caPath.value().c_str() : nullptr
));
return tls_check_res_none(
::SSL_CTX_load_verify_locations(
ctx_, caFile ? caFile.value().c_str() : nullptr,
caPath ? caPath.value().c_str() : nullptr
)
);
}
void tls_context::set_verify(verify_t mode) noexcept {

View File

@@ -57,7 +57,7 @@ unix_address::unix_address(const string& path) {
addr_.sun_family = ADDRESS_FAMILY;
// Remember, if len==MAX, there's no NUL terminator
const size_t n = std::min(path.length()+1, MAX_PATH_NAME);
const size_t n = std::min(path.length() + 1, MAX_PATH_NAME);
std::memcpy(addr_.sun_path, path.c_str(), n);
}
@@ -69,7 +69,7 @@ unix_address::unix_address(const string& path, error_code& ec) noexcept {
ec = error_code{};
addr_.sun_family = ADDRESS_FAMILY;
// Remember, if len==MAX, there's no NUL terminator
const size_t n = std::min(path.length()+1, MAX_PATH_NAME);
const size_t n = std::min(path.length() + 1, MAX_PATH_NAME);
std::memcpy(addr_.sun_path, path.c_str(), n);
}
}