# TlsConnectionBinding

`import { TlsConnectionBinding } from "destack:tls/binding";`

Connection binding family.

```ds title="TlsConnectionBinding"
export interface TlsConnectionBinding {
    openTlsConnection(context: TlsContextHandle, socket: SocketHandle, serverName?: &'a readonly string | undefined): Result<TlsConnectionHandle, HostError>;
    handshakeTlsConnection(connection: TlsConnectionHandle): Result<TlsHandshakeStatus, HostError>;
    readTlsConnection(connection: TlsConnectionHandle, buffer: &'a [uint8]): Result<uint64, HostError>;
    writeTlsConnection(connection: TlsConnectionHandle, buffer: &'a readonly [uint8]): Result<uint64, HostError>;
    shutdownTlsConnection(connection: TlsConnectionHandle): Result<void, HostError>;
    closeTlsConnection(connection: TlsConnectionHandle): Result<void, HostError>;
    readTlsAlpn(connection: TlsConnectionHandle): Result<uint8[], HostError>;
    readTlsPeerCertificatesPem(connection: TlsConnectionHandle): Result<uint8[], HostError>;
    exportTlsKeyingMaterial(connection: TlsConnectionHandle, label: &'a readonly string, context: &'b readonly [uint8], length: uint32): Result<uint8[], HostError>;
    readTlsResumptionState(connection: TlsConnectionHandle): Result<TlsResumptionState, HostError>;
}
```

[language/library/src/tls/binding/connection.ds:29:131](https://github.com/destack-sh/destack/blob/main/language/library/src/tls/binding/connection.ds#L29-L131)

## Members

### `openTlsConnection(context: TlsContextHandle, socket: SocketHandle, serverName?: &'a readonly string | undefined): Result<TlsConnectionHandle, HostError>`

Open one socket backed TLS connection.

### `handshakeTlsConnection(connection: TlsConnectionHandle): Result<TlsHandshakeStatus, HostError>`

Advance one TLS handshake state machine.

### `readTlsConnection(connection: TlsConnectionHandle, buffer: &'a [uint8]): Result<uint64, HostError>`

Read decrypted application bytes from one TLS connection.

### `writeTlsConnection(connection: TlsConnectionHandle, buffer: &'a readonly [uint8]): Result<uint64, HostError>`

Write plaintext application bytes to one TLS connection.

### `shutdownTlsConnection(connection: TlsConnectionHandle): Result<void, HostError>`

Shutdown one TLS connection.

### `closeTlsConnection(connection: TlsConnectionHandle): Result<void, HostError>`

Close one TLS connection.

### `readTlsAlpn(connection: TlsConnectionHandle): Result<uint8[], HostError>`

Read negotiated ALPN protocol bytes.

### `readTlsPeerCertificatesPem(connection: TlsConnectionHandle): Result<uint8[], HostError>`

Read the peer certificate chain in PEM encoding.

### `exportTlsKeyingMaterial(connection: TlsConnectionHandle, label: &'a readonly string, context: &'b readonly [uint8], length: uint32): Result<uint8[], HostError>`

Export keying material bytes for one TLS connection.

### `readTlsResumptionState(connection: TlsConnectionHandle): Result<TlsResumptionState, HostError>`

Return whether one connection resumed from cached state or ticket.
