ddn.net.ssh.wire
SSH wire-format codec (RFC 4251 section 5).
Bounded reader and writer for the SSH data types: byte, boolean, uint32, uint64, string, name-list, and mpint. Every read is bounds checked against the remaining input and against explicit limits before any slicing happens, so malformed or hostile input can only produce SshWireException, never unchecked growth or crashes.
The reader returns slices into the source buffer (no copies), which lets callers preserve the exact received bytes for transcript hashing during key exchange; callers must not outlive the buffer.
The codec has no socket or session dependencies and is fully usable from plain unit tests.
Types 4
Raised when wire data is malformed, truncated, non-canonical, or exceeds an explicit parser limit.
this(string msg, string file = __FILE__, size_t line = __LINE__)Constructs a wire-format exception.Parser limits enforced before any allocation or slicing.
Defaults follow the resource-limit inventory of the support matrix; specific readers may pass tighter or wider explicit limits.
Sequential reader over an SSH wire-format buffer.
All read methods consume from the current position and throw SshWireException on truncation, non-canonical encodings, or limit violations. Returned strings are slices into the input.
private const(ubyte)[] buf_private size_t pos_void requireFullyConsumed(string context = "message") @safeAsserts that the whole buffer was consumed.bool readBoolean() @safeReads a boolean. Any non-zero byte reads as true (RFC 4251 section 5); the writer never emits values other than 0 and 1.const(ubyte)[] readString(size_t maxLength = SshWireLimits.stringMax) @safeReads a length-prefixed string as a slice into the source buffer; no copy is made so exact received bytes stay available for transcript hashing.string readText(size_t maxLength = SshWireLimits.stringMax) @safeReads a length-prefixed string and converts it to text.string[] readNameList(size_t maxEntries = SshWireLimits.nameListMax) @safeReads a name-list: a string of comma-separated, non-empty, printable ASCII names.const(ubyte)[] readMpint(size_t maxBytes = SshWireLimits.mpintMax) @safeReads an mpint in its canonical two's-complement form and validates RFC 4251 section 5 encoding rules.this(const(ubyte)[] data)Constructs a reader over the given buffer.Growable writer for SSH wire-format values.
Writes enforce the same limits as the reader and emit only canonical encodings (booleans as 0/1, minimal mpints with sign padding).
private ubyte[] buf_void putString(const(ubyte)[] data,
size_t maxLength = SshWireLimits.stringMax) @safeWrites a length-prefixed string.void putString(string text,
size_t maxLength = SshWireLimits.stringMax) @safeWrites a length-prefixed string from text.void putNameList(scope const string[] names,
size_t maxEntries = SshWireLimits.nameListMax) @safeWrites a name-list of non-empty, printable ASCII names.void putMpint(const(ubyte)[] magnitude) @safeWrites an mpint in canonical form from a big-endian magnitude.Functions 1
string wireToText(const(ubyte)[] data) pure @trustedCopies wire bytes as text without pulling the cast into safe code.