ddn.net.tls.record

TLS record layer implementation.

Handles reading and writing TLS records (5-byte header + fragment). Supports both plaintext and encrypted records for TLS 1.2 and TLS 1.3.

Provides both blocking and non-blocking I/O methods. Non-blocking methods return TlsProgress to indicate when I/O is needed. Blocking methods are wrappers that throw on would-block conditions.

Types 2

structTlsRecord

TLS record structure.

Represents a single TLS record with content type, protocol version, and fragment data.

Fields
ContentType contentType
ProtocolVersion legacyVersion
ubyte[] fragment
Methods
TlsRecord parse(const(ubyte)[] data, out size_t consumed) @safe pure nothrowReads a TLS record from raw bytes.
ubyte[] serialize() @safe pure nothrowSerializes this record to raw bytes.

Record layer reads/writes TLS records over a transport.

Uses internal pre-allocated buffers for both reads and writes, supporting non-blocking I/O with partial record accumulation and partial write tracking.

Read buffer: 32 KB (accommodates 2 maximum-size TLS records). Write buffer: ~17 KB (one max record + overhead).

Memory guarantee: Maximum ~49 KB per RecordLayer instance.

Fields
TlsTransport transport_
ubyte[] readBuffer_
size_t readStart_
size_t readEnd_
ubyte[] writeBuffer_
size_t writePos_
size_t writeEnd_
Methods
TlsProgress tryReadRecord(ref TlsRecord record)Attempts to read the next complete TLS record.
TlsProgress tryWriteRecord(ContentType contentType, ProtocolVersion ver, const(ubyte)[] fragment)Attempts to write a TLS record to the transport.
TlsProgress tryWriteRaw(const(ubyte)[] wireData)Attempts to write pre-serialized wire data to the transport.
TlsProgress flushPendingWrite()Flushes pending write data to the transport.
bool hasPendingWrite() const pure nothrow @safe @nogcReturns: Whether there is pending write data that hasn't been fully sent to the transport.
TlsRecord readRecord()Reads the next complete TLS record from the transport.
void writeRecord(ContentType contentType, ProtocolVersion ver, const(ubyte)[] fragment)Writes a TLS record to the transport (blocking).
void writeRaw(const(ubyte)[] wireData)Writes a pre-serialized TLS record to the transport (blocking).
ubyte[] drainBuffer() @propertyReturns: Any buffered but unconsumed bytes from record reading.
void pushRecord(TlsRecord rec)Pushes a record back so the next read returns it.
size_t bufferedBytes() @property const pure nothrow @safe @nogcReturns: Number of bytes currently in the read buffer.
private void compactIfNeeded()
private void compactReadBuffer()
Constructors
this(TlsTransport transport)Constructs a RecordLayer over the given transport.