# SSLAdapter

<a id="ssladapter"></a>

# SSLAdapter

```cpp
#include <icy/net/ssladapter.h>

class SSLAdapter
```

[Defined in src/net/include/icy/net/ssladapter.h:38](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L38)

Manages the OpenSSL context and BIO buffers for an SSL socket connection.

## Friends

| Name | Description |
|------|-------------|
| [`net::SSLSocket`](#net-sslsocket)  |  |

---

<a id="net-sslsocket"></a>

### net::SSLSocket

```cpp
friend class net::SSLSocket
```

[Defined in src/net/include/icy/net/ssladapter.h:107](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L107)

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`SSLAdapter`](#ssladapter-1)  | Constructs the [SSLAdapter](#ssladapter) and associates it with the given socket. The socket pointer must remain valid for the lifetime of this adapter. |
|  | [`~SSLAdapter`](#ssladapter-2) `noexcept` |  |
|  | [`SSLAdapter`](#ssladapter-3)  | Deleted constructor. |
| [`SSLAdapter`](#ssladapter) & | [`operator=`](#operator-181)  | Deleted assignment operator. |
|  | [`SSLAdapter`](#ssladapter-4)  | Deleted constructor. |
| [`SSLAdapter`](#ssladapter) & | [`operator=`](#operator-182)  | Deleted assignment operator. |
| `void` | [`initClient`](#initclient)  | Initializes the SSL context as a client. |
| `void` | [`initServer`](#initserver)  | Initializes the SSL context as a server. |
| `bool` | [`initialized`](#initialized-2) `const` | Returns true when SSL context has been initialized. |
| `bool` | [`ready`](#ready) `const` | Returns true when the handshake is complete. |
| `void` | [`handshake`](#handshake)  | Start/continue the SSL handshake process. |
| `int` | [`available`](#available-3) `const` | Returns the number of bytes available in the SSL buffer for immediate reading. |
| `void` | [`shutdown`](#shutdown-4)  | Issues an orderly SSL shutdown. |
| `void` | [`flush`](#flush-10)  | Flushes the SSL read/write buffers. |
| `void` | [`setHostname`](#sethostname)  | Set the expected peer hostname for certificate verification. Must be called before [initClient()](#initclient) to enable hostname verification. |
| `void` | [`addIncomingData`](#addincomingdata)  | Feeds encrypted data received from the network into the SSL read BIO. Triggers a flush, which drives the handshake or decrypts and delivers plaintext to the socket via onRecv(). |
| `void` | [`addOutgoingData`](#addoutgoingdata)  | Queues plaintext data for encryption and transmission. |
| `void` | [`addOutgoingData`](#addoutgoingdata-1)  | Queues plaintext data for encryption and transmission. |
| `void` | [`addOutgoingData`](#addoutgoingdata-2)  | Moves plaintext data into the pending write buffer when possible. |

---

<a id="ssladapter-1"></a>

### SSLAdapter

```cpp
SSLAdapter(net::SSLSocket * socket)
```

[Defined in src/net/include/icy/net/ssladapter.h:44](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L44)

Constructs the [SSLAdapter](#ssladapter) and associates it with the given socket. The socket pointer must remain valid for the lifetime of this adapter.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `socket` | [`net::SSLSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#sslsocket) * | The owning [SSLSocket](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#sslsocket) that sends and receives raw data. |

---

<a id="ssladapter-2"></a>

### ~SSLAdapter

`noexcept`

```cpp
~SSLAdapter() noexcept
```

[Defined in src/net/include/icy/net/ssladapter.h:45](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L45)

---

<a id="ssladapter-3"></a>

### SSLAdapter

```cpp
SSLAdapter(const SSLAdapter &) = delete
```

[Defined in src/net/include/icy/net/ssladapter.h:47](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L47)

Deleted constructor.

---

<a id="operator-181"></a>

### operator=

```cpp
SSLAdapter & operator=(const SSLAdapter &) = delete
```

[Defined in src/net/include/icy/net/ssladapter.h:48](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L48)

Deleted assignment operator.

---

<a id="ssladapter-4"></a>

### SSLAdapter

```cpp
SSLAdapter(SSLAdapter &&) = delete
```

[Defined in src/net/include/icy/net/ssladapter.h:49](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L49)

Deleted constructor.

---

<a id="operator-182"></a>

### operator=

```cpp
SSLAdapter & operator=(SSLAdapter &&) = delete
```

[Defined in src/net/include/icy/net/ssladapter.h:50](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L50)

Deleted assignment operator.

---

<a id="initclient"></a>

### initClient

```cpp
void initClient()
```

[Defined in src/net/include/icy/net/ssladapter.h:53](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L53)

Initializes the SSL context as a client.

---

<a id="initserver"></a>

### initServer

```cpp
void initServer()
```

[Defined in src/net/include/icy/net/ssladapter.h:56](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L56)

Initializes the SSL context as a server.

---

<a id="initialized-2"></a>

### initialized

`const`

```cpp
bool initialized() const
```

[Defined in src/net/include/icy/net/ssladapter.h:59](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L59)

Returns true when SSL context has been initialized.

---

<a id="ready"></a>

### ready

`const`

```cpp
bool ready() const
```

[Defined in src/net/include/icy/net/ssladapter.h:62](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L62)

Returns true when the handshake is complete.

---

<a id="handshake"></a>

### handshake

```cpp
void handshake()
```

[Defined in src/net/include/icy/net/ssladapter.h:65](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L65)

Start/continue the SSL handshake process.

---

<a id="available-3"></a>

### available

`const`

```cpp
int available() const
```

[Defined in src/net/include/icy/net/ssladapter.h:69](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L69)

Returns the number of bytes available in the SSL buffer for immediate reading.

---

<a id="shutdown-4"></a>

### shutdown

```cpp
void shutdown()
```

[Defined in src/net/include/icy/net/ssladapter.h:72](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L72)

Issues an orderly SSL shutdown.

---

<a id="flush-10"></a>

### flush

```cpp
void flush()
```

[Defined in src/net/include/icy/net/ssladapter.h:75](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L75)

Flushes the SSL read/write buffers.

---

<a id="sethostname"></a>

### setHostname

```cpp
void setHostname(std::string_view hostname)
```

[Defined in src/net/include/icy/net/ssladapter.h:79](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L79)

Set the expected peer hostname for certificate verification. Must be called before [initClient()](#initclient) to enable hostname verification.

---

<a id="addincomingdata"></a>

### addIncomingData

```cpp
void addIncomingData(const char * data, size_t len)
```

[Defined in src/net/include/icy/net/ssladapter.h:86](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L86)

Feeds encrypted data received from the network into the SSL read BIO. Triggers a flush, which drives the handshake or decrypts and delivers plaintext to the socket via onRecv().

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `const char *` | Pointer to the encrypted bytes. |
| `len` | `size_t` | Number of bytes to feed. |

---

<a id="addoutgoingdata"></a>

### addOutgoingData

```cpp
void addOutgoingData(std::string_view data)
```

[Defined in src/net/include/icy/net/ssladapter.h:90](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L90)

Queues plaintext data for encryption and transmission.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `std::string_view` | String view of the plaintext payload. |

---

<a id="addoutgoingdata-1"></a>

### addOutgoingData

```cpp
void addOutgoingData(const char * data, size_t len)
```

[Defined in src/net/include/icy/net/ssladapter.h:95](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L95)

Queues plaintext data for encryption and transmission.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `const char *` | Pointer to the plaintext bytes. |
| `len` | `size_t` | Number of bytes to queue. |

---

<a id="addoutgoingdata-2"></a>

### addOutgoingData

```cpp
void addOutgoingData(Buffer && data)
```

[Defined in src/net/include/icy/net/ssladapter.h:98](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L98)

Moves plaintext data into the pending write buffer when possible.

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`net::SSLSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#sslsocket) * | [`_socket`](#_socket)  |  |
| `SSL *` | [`_ssl`](#_ssl)  |  |
| `BIO *` | [`_readBIO`](#_readbio)  | The incoming buffer we write encrypted SSL data into. |
| `BIO *` | [`_writeBIO`](#_writebio)  | The outgoing buffer we write to the socket. |
| `std::vector< char >` | [`_bufferOut`](#_bufferout)  | The outgoing payload to be encrypted and sent. |
| `std::string` | [`_hostname`](#_hostname)  | Expected peer hostname for verification. |

---

<a id="_socket"></a>

### _socket

```cpp
net::SSLSocket * _socket
```

Type: [`net::SSLSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#sslsocket) *

[Defined in src/net/include/icy/net/ssladapter.h:109](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L109)

---

<a id="_ssl"></a>

### _ssl

```cpp
SSL * _ssl
```

[Defined in src/net/include/icy/net/ssladapter.h:110](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L110)

---

<a id="_readbio"></a>

### _readBIO

```cpp
BIO * _readBIO
```

[Defined in src/net/include/icy/net/ssladapter.h:111](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L111)

The incoming buffer we write encrypted SSL data into.

---

<a id="_writebio"></a>

### _writeBIO

```cpp
BIO * _writeBIO
```

[Defined in src/net/include/icy/net/ssladapter.h:112](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L112)

The outgoing buffer we write to the socket.

---

<a id="_bufferout"></a>

### _bufferOut

```cpp
std::vector< char > _bufferOut
```

[Defined in src/net/include/icy/net/ssladapter.h:113](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L113)

The outgoing payload to be encrypted and sent.

---

<a id="_hostname"></a>

### _hostname

```cpp
std::string _hostname
```

[Defined in src/net/include/icy/net/ssladapter.h:114](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L114)

Expected peer hostname for verification.

## Protected Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`handleError`](#handleerror)  |  |
| `void` | [`flushReadBIO`](#flushreadbio)  |  |
| `void` | [`flushWriteBIO`](#flushwritebio)  |  |

---

<a id="handleerror"></a>

### handleError

```cpp
void handleError(int rc)
```

[Defined in src/net/include/icy/net/ssladapter.h:101](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L101)

---

<a id="flushreadbio"></a>

### flushReadBIO

```cpp
void flushReadBIO()
```

[Defined in src/net/include/icy/net/ssladapter.h:103](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L103)

---

<a id="flushwritebio"></a>

### flushWriteBIO

```cpp
void flushWriteBIO()
```

[Defined in src/net/include/icy/net/ssladapter.h:104](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/ssladapter.h#L104)
