Runs the client handshake over reader and writer and checks the server's certificate against
server_name (which is also sent as the SNI name; "" sends none, and with verify_name off the
name is not checked). On success the stream owns the connection:
close closes it. On an error nothing is closed, the connection is the caller's to close.
- config: an initialised config (
tls_config_init). - reader: where the bytes from the server come from.
- writer: where the bytes to the server go.
- server_name: the host name to check the certificate against and send as SNI.
Io :: #import "Extensions/Io";
Io.io_run(() {
config: Tls_Config;
tls_config_init(*config);
defer tls_config_free(*config);
tcp, io_error := Io.connect("example.com:443");
assert(io_error == .NONE);
stream, error := tls_connect(*config, Io.reader_of(tcp), Io.writer_of(tcp), "example.com");
if error.kind != .NONE {
Io.close(tcp);
return;
}
defer close(stream);
write(stream, "hello");
});This one is only checked to compile, not run.
tls_connect :: (
config: *Tls_Config,
reader: Io.Reader,
writer: Io.Writer,
server_name: string
) -> (*Tls_Stream, Tls_Error)
Runs the client handshake over reader and writer and checks the server's certificate against
server_name (which is also sent as the SNI name; "" sends none, and with verify_name off the
name is not checked). On success the stream owns the connection:
close closes it. On an error nothing is closed, the connection is the caller's to close.
Parameters
- config: *Tls_Config
- an initialised config (
tls_config_init). - reader: Io.Reader
- where the bytes from the server come from.
- writer: Io.Writer
- where the bytes to the server go.
- server_name: string
- the host name to check the certificate against and send as SNI.
Returns
Io :: #import "Extensions/Io";
Io.io_run(() {
config: Tls_Config;
tls_config_init(*config);
defer tls_config_free(*config);
tcp, io_error := Io.connect("example.com:443");
assert(io_error == .NONE);
stream, error := tls_connect(*config, Io.reader_of(tcp), Io.writer_of(tcp), "example.com");
if error.kind != .NONE {
Io.close(tcp);
return;
}
defer close(stream);
write(stream, "hello");
});This one is only checked to compile, not run.