Wrapper

class siotls.wrapper.WrappedSocket

Bind a TLSConnection to a TCP socket and get a file-like object with read(), write(), close().

conf = TLSConfiguration('client')
conn = TLSConnection(conf, server_hostname='example.com')
with socket.create_connection(('example.com', 443)) as sock:
    sock.settimeout(5)
    with conn.wrap(sock) as sfile:
        sfile.write(b"GET / HTTP/1.0\r\nHost: example.com\r\n\r\n")
        while conn.is_connected():
            print(sfile.read().decode(errors='replace'))
__init__(conn, sock)
Parameters:
close()

Signal the peer we won’t send any other message and then close the TCP socket.

There’s a risk of data loss / truncation attack if this method is called before the peer closed its sending side, use read().

Return type:

None

conn: siotls.connection.TLSConnection
do_handhskake()

Take over the TCP socket to perform the TLS handshake, sending and receiving as many TCP segments as necessary.

Return type:

None

read()

Read from the TCP socket, decrypt and return the incomming application data.

Handle the protocol messages (key update, heartbeat, …) automatically, sending replies when necessary.

Return empty bytes when the peer closed its sending side.

Return type:

bytes

sock: socket.socket
write(data)

Encrypt the data and send it over the TCP socket.

Parameters:

data (bytes)

Return type:

None