summaryrefslogtreecommitdiff
path: root/modules/io-tls/c++/tls.hpp
blob: 5082ee9e88b0b51640fd39dac1eacfb12eb5e238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once

#include <forstio/common.hpp>
#include <forstio/io/io.hpp>

#include <optional>
#include <variant>

namespace saw {
namespace net {
template<typename T = net::Os>
struct Tls {};
}

class tls;

/**
* tls context class.
* Provides tls network class which ensures the usage of tls encrypted connections
*/
class tls {
private:
	class impl;
	own<impl> impl_;
public:
	tls();
	~tls();

	struct version {
		struct tls_1_0{};
		struct tls_1_1{};
		struct tls_1_2{};
	};

	struct options {
	public:
		version version;
	};

	impl &get_impl();
private:
	options options_;
};

template<typename T>
class network_address<net::Tls<T>> final {
private:
	own<network_address<T>> internal_;
public:
	network_address(own<network_address<T>> internal__):
		internal_{std::move(internal__)}
	{}

	network_address<T>& get_handle() {
		return *internal_;
	}
};

template<typename T>
class network<net::Tls<T>> {
public:
	virtual ~network() = default;

	/**
	 * Resolve the provided string and uint16 to the preferred storage method
	 */
	virtual conveyor<own<network_address<net::Tls<T>>>>
	resolve_address(const std::string &addr, uint16_t port_hint = 0) = 0;
	
	/**
	 * Parse the provided string and uint16 to the preferred storage method
	 * Since no dns request is made here, no async conveyors have to be used.
	 */
	virtual error_or<own<network_address<net::Tls<T>>>>
	parse_address(const std::string &addr, uint16_t port_hint = 0) = 0;

	/**
	 * Set up a listener on this address
	 */
	virtual error_or<own<server<net::Tls<T>>>> listen(network_address<net::Tls<T>> &bind_addr) = 0;

	/**
	 * Connect to a remote address
	 */
	virtual conveyor<own<io_stream<net::Tls<T>>>> connect(network_address<net::Tls<T>> &address) = 0;
};

template<typename T = net::Os>
error_or<own<network<net::Tls<T>>>> setup_tls_network(network<T> &network);

} // namespace saw

#include "tls.tmpl.hpp"