Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
tls_policy_example.cpp
Go to the documentation of this file.
1/*****************************************************************************
2BSD 3-Clause License
3
4Copyright (c) 2024, 🍀☀🌕🌥 🌊
5All rights reserved.
6*****************************************************************************/
7
26
27#include <iostream>
28#include <string>
29
30using namespace kcenon::network;
31
32// Compile-time TLS policy demonstration
33template <typename TlsPolicy>
34void describe_policy(const std::string& label)
35{
36 std::cout << " " << label << ": TLS "
37 << (TlsPolicy::enabled ? "enabled" : "disabled") << std::endl;
38}
39
40int main()
41{
42 std::cout << "=== TLS Policy Example ===" << std::endl;
43
44 // 1. No TLS (plain-text)
45 std::cout << "\n1. Compile-time policy inspection:" << std::endl;
48
49 // 2. TLS configuration
50 std::cout << "\n2. TLS enabled configuration:" << std::endl;
51 policy::tls_enabled tls_config;
52 tls_config.cert_path = "/etc/ssl/certs/server.crt";
53 tls_config.key_path = "/etc/ssl/private/server.key";
54 tls_config.ca_path = "/etc/ssl/certs/ca-bundle.crt";
55 tls_config.verify_peer = true;
56
57 std::cout << " Certificate: " << tls_config.cert_path << std::endl;
58 std::cout << " Private key: " << tls_config.key_path << std::endl;
59 std::cout << " CA bundle: " << tls_config.ca_path << std::endl;
60 std::cout << " Verify peer: " << (tls_config.verify_peer ? "yes" : "no") << std::endl;
61
62 // 3. Static assertions
63 std::cout << "\n3. Compile-time checks:" << std::endl;
64 static_assert(!policy::no_tls::enabled, "no_tls must have enabled=false");
65 static_assert(policy::tls_enabled::enabled, "tls_enabled must have enabled=true");
66 std::cout << " All static assertions passed" << std::endl;
67
68 std::cout << "\nDone." << std::endl;
69 return 0;
70}
Main namespace for all Network System components.
static constexpr bool enabled
Definition tls_policy.h:40
Policy type indicating TLS/SSL encryption is enabled.
Definition tls_policy.h:61
static constexpr bool enabled
Definition tls_policy.h:62
Policy-based TLS configuration (no_tls, require_tls, optional_tls).
void describe_policy(const std::string &label)
int main()