← All compilation units

Flyology.Postgres.Transports.TLS_Sockets

Description

Socket transport that starts in plaintext and can be upgraded to TLS.

Is_Encrypted

function Is_Encrypted (Item : TLS_Socket_Transport) return Boolean

Report whether Upgrade_TLS completed successfully.

Parameters
Item

Transport whose current mode is queried.

Return value

True when subsequent traffic uses the TLS connection.

Receive_Exactly

procedure Receive_Exactly
  (Item    : in out TLS_Socket_Transport;
   Data    : out Ada.Streams.Stream_Element_Array;
   Timeout : Duration;
   On_Wait : access Wait_Observer'Class := null)

Fill Data through the active plaintext or encrypted channel. Without an observer the channel is read in one call. With one, it is read in chunks under the same deadline so the observer runs between them, and may send on this transport before the buffer is full.

Parameters
Item

Transport to read.

Data

Buffer filled with exactly Data'Length bytes.

Timeout

Maximum time allowed for the complete read.

On_Wait

Observer notified between chunks while Data fills.

Send_All

procedure Send_All
  (Item    : in out TLS_Socket_Transport;
   Data    : Ada.Streams.Stream_Element_Array;
   Timeout : Duration)

Write every byte of Data through the active channel.

Parameters
Item

Transport to write.

Data

Complete buffer to transmit.

Timeout

Maximum time allowed for the complete write.

TLS_Socket_Transport

type TLS_Socket_Transport
  (Socket : not null access Flyology.IO.Sockets.Socket_Type)
is limited new TLS_Upgradable_Transport with private;

Starts by borrowing Socket as plaintext. Upgrade_TLS transfers Socket into the TLS connection, which then remains the sole closing owner.

Upgrade_TLS

procedure Upgrade_TLS
  (Item        : in out TLS_Socket_Transport;
   Backend     : in out Flyology.IO.TLS.Provider'Class;
   Server_Name : String;
   Timeout     : Duration)

Transfer Socket into a verified TLS connection.

Parameters
Item

Plaintext transport to upgrade exactly once.

Backend

TLS provider and trust configuration to use.

Server_Name

DNS name checked during certificate verification.

Timeout

Maximum time allowed for the handshake.

Raised exceptions
Program_Error

Item has already been upgraded.