For the latest stable version, please use Emilua API 0.10!

tls.socket

tls_ctx = tls.context.new('tlsv13')

local s = ip.tcp.socket.new()
ip.connect(s, ip.tcp.get_address_info('www.example.com', 'https'))
s = tls.socket.new(s, tls_ctx)
s:client_handshake()
s = http.socket.new(s)

local req = http.request.new()
local res = http.response.new()
req.headers.host = 'www.example.com'

s:write_request(req)
s:read_response(res)

Functions

new(sock: ip.tcp.socket, tls_ctx: tls.context) → tls.socket

Constructor.

client_handshake(self)

Perform the TLS client handshake and suspend current fiber until operation finishes.

server_handshake(self)

Perform the TLS server handshake and suspend current fiber until operation finishes.

read_some(self, buffer: byte_span) → integer

Read data from the stream socket and blocks current fiber until it completes or errs.

Returns the number of bytes read.

write_some(self, buffer: byte_span) → integer

Write data to the stream socket and blocks current fiber until it completes or errs.

Returns the number of bytes written.

set_server_name(self, hostname: string)

Sets the server name indication.

set_verify_callback(self, callback: string[, callback_options…​])

Set the callback used to verify peer certificates.

For now only one callback is supported:

"host_name_verification"

callback_options will be a single string containing the host name.

set_verify_depth(self, depth: integer)

Set the peer verification depth.

set_verify_mode(self, mode: string)

Set the peer verification mode.

mode might be one of the following:

  • "none".

  • "peer".

  • "fail_if_no_peer_cert".

  • "client_once".