Tls module

tls_accept

procedureextensionexperimentalSource

Runs the server handshake. The config needs a certificate and key. On success the stream owns the connection; on an error the caller closes it.

Example↗
Io :: #import "Extensions/Io";

// `config` has a certificate chain and private key; `listener` is an Io.Tcp_Listener.
serve_one :: (config: *Tls_Config, listener: Io.Tcp_Listener) {
    tcp, io_error := Io.accept(listener);
    if io_error != .NONE return;

    stream, error := tls_accept(config, Io.reader_of(tcp), Io.writer_of(tcp));
    if error.kind != .NONE {
        Io.close(tcp);
        return;
    }
    defer close(stream);

    write(stream, "welcome");
}

This one is only checked to compile, not run.

tls_accept :: (
    config: *Tls_Config,
    reader: Io.Reader,
    writer: Io.Writer
) -> (*Tls_Stream, Tls_Error)

Runs the server handshake. The config needs a certificate and key. On success the stream owns the connection; on an error the caller closes it.

Parameters

config: *Tls_Config
an initialised config with a certificate and key.
reader: Io.Reader
where the bytes from the client come from.
writer: Io.Writer
where the bytes to the client go.

Returns

Example↗
Io :: #import "Extensions/Io";

// `config` has a certificate chain and private key; `listener` is an Io.Tcp_Listener.
serve_one :: (config: *Tls_Config, listener: Io.Tcp_Listener) {
    tcp, io_error := Io.accept(listener);
    if io_error != .NONE return;

    stream, error := tls_accept(config, Io.reader_of(tcp), Io.writer_of(tcp));
    if error.kind != .NONE {
        Io.close(tcp);
        return;
    }
    defer close(stream);

    write(stream, "welcome");
}

This one is only checked to compile, not run.

See also