tlsada_2.5.2_7e2dcb92/src/tls-contexts-client.ads

 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
-- The context used for making and managing Client connections.
--
--
-- Copyright (c) 2022 nytpu <alex [at] nytpu.com>
-- SPDX-License-Identifier: MPL-2.0
-- For more license details, see LICENSE or <https://www.mozilla.org/en-US/MPL/2.0/>.

pragma Ada_2012;

with GNAT.Sockets;  use GNAT.Sockets;

private with Ada.Finalization;

package TLS.Contexts.Client is

	type Client_Context is new Context with private;

	-- Connect to a given hostname and port using a given context
	procedure Connect
		(Ctx : in out Client_Context; Host : String; Port : Port_Number)
		with
			Pre => Ctx.Is_Initialized and Ctx.Is_Configued and not Ctx.Is_Connected,
			Post => Ctx.Is_Connected;

	-- Connect to a given hostname and port using a given context, in the same
	-- manner as the other Connect; however this will also specify an
	-- additional server name, for the case where the TLS name differs from the
	-- DNS hostname.
	procedure Connect (
		Ctx : in out Client_Context;
		Host : String;
		Port : Port_Number;
		Server_Name : String
	) with
		Pre => Ctx.Is_Initialized and Ctx.Is_Configued and not Ctx.Is_Connected,
		Post => Ctx.Is_Connected;

	-- Upgrade an existing socket connection to use TLS.  The server name is
	-- used for TLS' server name indication.  If this procedure is used to
	-- establish a connection then the socket will not be closed when calling
	-- Close.
	procedure Connect (
		Ctx : in out Client_Context;
		Socket : GNAT.Sockets.Socket_Type;
		Server_Name : String
	) with
		Pre =>
			Ctx.Is_Initialized and Ctx.Is_Configued and not Ctx.Is_Connected,
		Post => Ctx.Is_Connected;

	-- Indicate whether a TLS session has been resumed during the handshake
	-- with the connected server
	function Session_Resumed (Ctx : Client_Context) return Boolean
		with Pre => Ctx.Is_Connected;


private
	type Controlled_Mixin (Enclosing : access Client_Context) is
		new Ada.Finalization.Limited_Controlled with null record;
	overriding procedure Initialize (Object : in out Controlled_Mixin);

	type Client_Context is new Context with record
		-- Client_Context'Access refers to the actual enclosing instance!
		Mix_In : Controlled_Mixin(Enclosing => Client_Context'Access);
	end record;

end TLS.Contexts.Client;