Skip to content

Commit 367cad8

Browse files
committed
Styling + TlsContext
- Added TlsContext to encapsulate a SSL_CTX - Reworked the TlsSocket constructors to use the new TlsContext - Removed useless data members of TlsSocket
1 parent 254b13c commit 367cad8

File tree

22 files changed

+549
-323
lines changed

22 files changed

+549
-323
lines changed

.clang-tidy

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
Checks: '
22
*,
33
-llvmlibc-*,
4+
-android-*,
5+
-altera-*,
6+
-fuchsia*,
47
-google-readability-todo,
5-
-fuchsia-default-arguments-calls,
6-
-fuchsia-default-arguments-declarations,
78
-cppcoreguidelines-init-variables,
89
-cppcoreguidelines-pro-type-reinterpret-cast,
9-
-android-*,
10-
-altera-*,
1110
-llvm-namespace-comment,
1211
-readability-implicit-bool-conversion,
1312
-google-explicit-constructor,
14-
-fuchsia-overloaded-operator,
13+
-abseil-string-find-str-contains,
14+
-readability-avoid-return-with-void-value,
15+
-readability-convert-member-functions-to-static,
1516
1617
-google-readability-braces-around-statements,
1718
-google-readability-namespace-comments,
19+
-hicpp-special-member-functions,
1820
-hicpp-braces-around-statements,
19-
-hicpp-explicit-conversions,
20-
-fuchsia-trailing-return
21+
-hicpp-explicit-conversions
2122
'
2223

2324
WarningsAsErrors: 'bugprone-exception-escape'
2425
FormatStyle: 'none' # TODO: Replace with 'file' once we have a proper .clang-format file
2526
InheritParentConfig: true
2627
CheckOptions:
2728
misc-include-cleaner.MissingIncludes: 'false'
28-
misc-include-cleaner.IgnoreHeaders: 'CppSockets/OSDetection\.hpp'
29+
misc-include-cleaner.IgnoreHeaders: 'CppSockets/OSDetection.*'
2930

3031
bugprone-argument-comment.StrictMode: 1
3132

@@ -34,5 +35,7 @@ CheckOptions:
3435

3536
readability-identifier-naming.NamespaceCase: CamelCase
3637

37-
readability-identifier-length.IgnoredVariableNames: "^(fd|nb|ss)$"
38-
readability-identifier-length.IgnoredParameterNames: "^([n]|fd)$"
38+
readability-identifier-length.IgnoredVariableNames: "^(fd|nb|n|ss|ec|is|os|_.*)$"
39+
readability-identifier-length.IgnoredParameterNames: "^(fd|n|is|os|_.*)$"
40+
41+
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true

.github/workflows/cmake-multi-platform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
clang-tidy:
9696
needs: 'build'
9797
runs-on: ubuntu-latest
98-
if: always() && github.event_name == 'pull-request'
98+
if: always() && github.event_name == 'pull_request'
9999

100100
steps:
101101
- name: Checkout Code

.github/workflows/windows-vcpkg/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ runs:
2727
shell: powershell
2828
run: |
2929
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
30-
vcpkg install --debug
30+
vcpkg install
3131
3232
- name: Always Save VCPKG Cache (Windows)
3333
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Author Francois Michaut
55
##
66
## Started on Sun Aug 28 19:26:51 2022 Francois Michaut
7-
## Last update Tue Aug 5 19:07:23 2025 Francois Michaut
7+
## Last update Wed Aug 20 17:05:18 2025 Francois Michaut
88
##
99
## CMakeLists.txt : CMake to build the CppSockets library
1010
##
@@ -21,15 +21,23 @@ project(LibCppSockets VERSION 0.1.0 LANGUAGES C CXX)
2121
configure_file(include/CppSockets/Version.hpp.in include/CppSockets/Version.hpp)
2222

2323
add_library(cppsockets
24+
source/Tls/Certificate.cpp
25+
source/Tls/Context.cpp
26+
source/Tls/Utils.cpp
27+
source/Tls/Socket.cpp
28+
2429
source/Address.cpp
25-
source/Certificate.cpp
2630
source/IPv4.cpp
27-
source/SSL_Utils.cpp
2831
source/Socket.cpp
2932
source/SocketInit.cpp
30-
source/TlsSocket.cpp
3133
)
32-
target_include_directories(cppsockets PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
34+
target_include_directories(cppsockets
35+
PUBLIC
36+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
37+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
38+
PRIVATE
39+
${PROJECT_SOURCE_DIR}/private
40+
)
3341

3442
find_package(OpenSSL 3.0 COMPONENTS SSL)
3543
target_link_libraries(cppsockets OpenSSL::SSL)

include/CppSockets/Address.hpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sun Feb 13 17:09:05 2022 Francois Michaut
7-
** Last update Sat Dec 9 08:52:22 2023 Francois Michaut
7+
** Last update Wed Aug 20 12:57:17 2025 Francois Michaut
88
**
99
** Address.hpp : Interface to represent network addresses
1010
*/
@@ -20,43 +20,40 @@
2020
namespace CppSockets {
2121
class IAddress {
2222
public:
23-
[[nodiscard]] virtual auto getAddress() const -> std::uint32_t = 0;
24-
[[nodiscard]] virtual auto getFamily() const -> int = 0;
25-
[[nodiscard]] virtual auto toString() const -> const std::string & = 0;
23+
virtual ~IAddress() = default;
24+
25+
[[nodiscard]] virtual auto get_address() const -> std::uint32_t = 0;
26+
[[nodiscard]] virtual auto get_family() const -> int = 0;
27+
[[nodiscard]] virtual auto to_string() const -> const std::string & = 0;
2628
};
2729

2830
class IEndpoint {
2931
public:
30-
[[nodiscard]] virtual auto getPort() const -> std::uint16_t = 0;
31-
[[nodiscard]] virtual auto getAddr() const -> const IAddress & = 0;
32-
[[nodiscard]] virtual auto toString() const -> const std::string & = 0;
32+
virtual ~IEndpoint() = default;
33+
34+
[[nodiscard]] virtual auto get_port() const -> std::uint16_t = 0;
35+
[[nodiscard]] virtual auto get_addr() const -> const IAddress & = 0;
36+
[[nodiscard]] virtual auto to_string() const -> const std::string & = 0;
3337

3438
protected:
35-
[[nodiscard]] auto makeString() const -> std::string;
39+
[[nodiscard]] auto make_string() const -> std::string;
3640
};
3741

3842
template <class T>
3943
class Endpoint : public IEndpoint {
44+
// TODO: Replace with new C++ requires
4045
static_assert(std::is_base_of<IAddress, T>::value,
41-
"Endpoint address must derive from IAddress"
46+
"Endpoint address must derive from IAddress"
4247
);
4348
public:
4449
Endpoint(T addr, std::uint16_t port) :
45-
addr(std::move(addr)), port(port), str(makeString())
50+
addr(std::move(addr)), port(port), str(make_string())
4651
{};
47-
virtual ~Endpoint() = default;
48-
49-
[[nodiscard]] auto getPort() const -> std::uint16_t override {
50-
return port;
51-
}
52-
53-
[[nodiscard]] auto getAddr() const -> const T & override {
54-
return addr;
55-
}
52+
~Endpoint() override = default;
5653

57-
[[nodiscard]] auto toString() const -> const std::string & override {
58-
return str;
59-
}
54+
[[nodiscard]] auto get_port() const -> std::uint16_t override { return port; }
55+
[[nodiscard]] auto get_addr() const -> const T & override { return addr; }
56+
[[nodiscard]] auto to_string() const -> const std::string & override { return str; }
6057
private:
6158
T addr;
6259
std::uint16_t port;

include/CppSockets/IPv4.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sun Feb 13 17:05:02 2022 Francois Michaut
7-
** Last update Sat Nov 11 16:58:19 2023 Francois Michaut
7+
** Last update Wed Aug 20 12:57:35 2025 Francois Michaut
88
**
99
** IPv4.hpp : Class used to represent and manipulate IPv4 addresses
1010
*/
@@ -19,10 +19,9 @@ namespace CppSockets {
1919
explicit IPv4(std::uint32_t addr);
2020
IPv4(const char *addr); // TODO add support for string. Maybe string_view ?
2121

22-
23-
[[nodiscard]] auto getAddress() const -> std::uint32_t override;
24-
[[nodiscard]] auto getFamily() const -> int override;
25-
[[nodiscard]] auto toString() const -> const std::string & override;
22+
[[nodiscard]] auto get_address() const -> std::uint32_t override;
23+
[[nodiscard]] auto get_family() const -> int override;
24+
[[nodiscard]] auto to_string() const -> const std::string & override;
2625

2726
private:
2827
std::uint32_t addr;

include/CppSockets/SSL_Utils.hpp

Lines changed: 0 additions & 53 deletions
This file was deleted.

include/CppSockets/Socket.hpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
** Author Francois Michaut
55
**
66
** Started on Sat Jan 15 01:17:42 2022 Francois Michaut
7-
** Last update Tue Aug 5 00:00:48 2025 Francois Michaut
7+
** Last update Wed Aug 20 14:01:21 2025 Francois Michaut
88
**
99
** Socket.hpp : Portable C++ socket class
1010
*/
1111

1212
#pragma once
1313

1414
#include "CppSockets/OSDetection.hpp"
15-
#include "CppSockets/SocketInit.hpp"
15+
#include "CppSockets/internal/SocketInit.hpp"
1616

1717
// TODO: move the RawSocketType in CppSockets namespace
1818
#ifdef OS_WINDOWS
@@ -65,18 +65,13 @@ namespace CppSockets {
6565

6666
void set_blocking(bool val);
6767

68-
[[nodiscard]]
69-
auto get_fd() const -> RawSocketType { return m_sockfd; }
70-
[[nodiscard]]
71-
auto get_type() const -> int { return m_type; }
72-
[[nodiscard]]
73-
auto get_domain() const -> int { return m_domain; }
74-
[[nodiscard]]
75-
auto get_protocol() const -> int { return m_protocol; }
68+
[[nodiscard]] auto get_fd() const -> RawSocketType { return m_sockfd; }
69+
[[nodiscard]] auto get_type() const -> int { return m_type; }
70+
[[nodiscard]] auto get_domain() const -> int { return m_domain; }
71+
[[nodiscard]] auto get_protocol() const -> int { return m_protocol; }
7672
// TODO: Allow to get Endpoint
7773

78-
[[nodiscard]]
79-
auto connected() const -> bool { return m_is_connected; }
74+
[[nodiscard]] auto connected() const -> bool { return m_is_connected; }
8075

8176
static auto get_errno() -> int;
8277
static auto strerror(int err) -> char *;

0 commit comments

Comments
 (0)