1 /**
2 SSL stream peer.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.streampeerssl;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.streampeer;
25 import godot.reference;
26 import godot.cryptokey;
27 import godot.x509certificate;
28 /**
29 SSL stream peer.
30 
31 This object can be used to connect to an SSL server or accept a single SSL client connection.
32 */
33 @GodotBaseClass struct StreamPeerSSL
34 {
35 	package(godot) enum string _GODOT_internal_name = "StreamPeerSSL";
36 public:
37 @nogc nothrow:
38 	union { /** */ godot_object _godot_object; /** */ StreamPeer _GODOT_base; }
39 	alias _GODOT_base this;
40 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
41 	package(godot) __gshared bool _classBindingInitialized = false;
42 	package(godot) static struct GDNativeClassBinding
43 	{
44 		__gshared:
45 		@GodotName("accept_stream") GodotMethod!(GodotError, StreamPeer, CryptoKey, X509Certificate, X509Certificate) acceptStream;
46 		@GodotName("connect_to_stream") GodotMethod!(GodotError, StreamPeer, bool, String, X509Certificate) connectToStream;
47 		@GodotName("disconnect_from_stream") GodotMethod!(void) disconnectFromStream;
48 		@GodotName("get_status") GodotMethod!(StreamPeerSSL.Status) getStatus;
49 		@GodotName("is_blocking_handshake_enabled") GodotMethod!(bool) isBlockingHandshakeEnabled;
50 		@GodotName("poll") GodotMethod!(void) poll;
51 		@GodotName("set_blocking_handshake_enabled") GodotMethod!(void, bool) setBlockingHandshakeEnabled;
52 	}
53 	/// 
54 	pragma(inline, true) bool opEquals(in StreamPeerSSL other) const
55 	{ return _godot_object.ptr is other._godot_object.ptr; }
56 	/// 
57 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
58 	{ _godot_object.ptr = n; return null; }
59 	/// 
60 	pragma(inline, true) bool opEquals(typeof(null) n) const
61 	{ return _godot_object.ptr is n; }
62 	/// 
63 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
64 	mixin baseCasts;
65 	/// Construct a new instance of StreamPeerSSL.
66 	/// Note: use `memnew!StreamPeerSSL` instead.
67 	static StreamPeerSSL _new()
68 	{
69 		static godot_class_constructor constructor;
70 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("StreamPeerSSL");
71 		if(constructor is null) return typeof(this).init;
72 		return cast(StreamPeerSSL)(constructor());
73 	}
74 	@disable new(size_t s);
75 	/// 
76 	enum Status : int
77 	{
78 		/**
79 		A status representing a $(D StreamPeerSSL) that is disconnected.
80 		*/
81 		statusDisconnected = 0,
82 		/**
83 		A status representing a $(D StreamPeerSSL) during handshaking.
84 		*/
85 		statusHandshaking = 1,
86 		/**
87 		A status representing a $(D StreamPeerSSL) that is connected to a host.
88 		*/
89 		statusConnected = 2,
90 		/**
91 		A status representing a $(D StreamPeerSSL) in error state.
92 		*/
93 		statusError = 3,
94 		/**
95 		An error status that shows a mismatch in the SSL certificate domain presented by the host and the domain requested for validation.
96 		*/
97 		statusErrorHostnameMismatch = 4,
98 	}
99 	/// 
100 	enum Constants : int
101 	{
102 		statusDisconnected = 0,
103 		statusHandshaking = 1,
104 		statusConnected = 2,
105 		statusError = 3,
106 		statusErrorHostnameMismatch = 4,
107 	}
108 	/**
109 	Accepts a peer connection as a server using the given `private_key` and providing the given `certificate` to the client. You can pass the optional `chain` parameter to provide additional CA chain information along with the certificate.
110 	*/
111 	GodotError acceptStream(StreamPeer stream, CryptoKey private_key, X509Certificate certificate, X509Certificate chain = X509Certificate.init)
112 	{
113 		checkClassBinding!(typeof(this))();
114 		return ptrcall!(GodotError)(GDNativeClassBinding.acceptStream, _godot_object, stream, private_key, certificate, chain);
115 	}
116 	/**
117 	Connects to a peer using an underlying $(D StreamPeer) `stream`. If `validate_certs` is `true`, $(D StreamPeerSSL) will validate that the certificate presented by the peer matches the `for_hostname`.
118 	$(B Note:) Specifying a custom `valid_certificate` is not supported in HTML5 exports due to browsers restrictions.
119 	*/
120 	GodotError connectToStream(StreamPeer stream, in bool validate_certs = false, in String for_hostname = gs!"", X509Certificate valid_certificate = X509Certificate.init)
121 	{
122 		checkClassBinding!(typeof(this))();
123 		return ptrcall!(GodotError)(GDNativeClassBinding.connectToStream, _godot_object, stream, validate_certs, for_hostname, valid_certificate);
124 	}
125 	/**
126 	Disconnects from host.
127 	*/
128 	void disconnectFromStream()
129 	{
130 		checkClassBinding!(typeof(this))();
131 		ptrcall!(void)(GDNativeClassBinding.disconnectFromStream, _godot_object);
132 	}
133 	/**
134 	Returns the status of the connection. See $(D status) for values.
135 	*/
136 	StreamPeerSSL.Status getStatus() const
137 	{
138 		checkClassBinding!(typeof(this))();
139 		return ptrcall!(StreamPeerSSL.Status)(GDNativeClassBinding.getStatus, _godot_object);
140 	}
141 	/**
142 	
143 	*/
144 	bool isBlockingHandshakeEnabled() const
145 	{
146 		checkClassBinding!(typeof(this))();
147 		return ptrcall!(bool)(GDNativeClassBinding.isBlockingHandshakeEnabled, _godot_object);
148 	}
149 	/**
150 	Poll the connection to check for incoming bytes. Call this right before $(D StreamPeer.getAvailableBytes) for it to work properly.
151 	*/
152 	void poll()
153 	{
154 		checkClassBinding!(typeof(this))();
155 		ptrcall!(void)(GDNativeClassBinding.poll, _godot_object);
156 	}
157 	/**
158 	
159 	*/
160 	void setBlockingHandshakeEnabled(in bool enabled)
161 	{
162 		checkClassBinding!(typeof(this))();
163 		ptrcall!(void)(GDNativeClassBinding.setBlockingHandshakeEnabled, _godot_object, enabled);
164 	}
165 	/**
166 	
167 	*/
168 	@property bool blockingHandshake()
169 	{
170 		return isBlockingHandshakeEnabled();
171 	}
172 	/// ditto
173 	@property void blockingHandshake(bool v)
174 	{
175 		setBlockingHandshakeEnabled(v);
176 	}
177 }