Skip to content

ssh-encoding: extract a shared Decoder<R> [BREAKING] - #618

Merged
tarcieri merged 1 commit into
masterfrom
ssh-encoding/decoder-type
Nov 10, 2026
Merged

tarcieri merged 1 commit into
masterfrom
ssh-encoding/decoder-type

Conversation

@tarcieri

Copy link
Copy Markdown
Member

Move nested decoding, length bounds, completion checks, and failure state into a shared Decoder<R> type which owns the underlying reader.

This removes considerable complexity from the reader types, including their individual Reader::read_prefixed implementations and the supporting macro, leaving them responsible only for supplying bytes and reporting the remaining length.

Nested decoding now uses a common read_nested implementation which temporarily narrows the decoder's bounds. Each nesting level uses the same Decoder<R> type, preserving no_alloc support without the recursively nested generic reader types that previously caused monomorphization bloat.

This is a breaking change: Decode implementations now accept &mut Decoder<impl Reader>, which is slightly uglier from an API perspective but enables a much better underlying implementation.

A blanket From<R> implementation keeps call sites concise by allowing Readers to be converted into a Decoder with into()..

We are also motivated by #615 to make another breaking ssh-encoding release before the next ssh-key release: making the remaining infallible Mpint conversions fallible would allow its size limits to be enforced consistently.

Because this is a breaking change, the versions of ssh-cipher, ssh-derive, and ssh-encoding have all been bumped to v0.4.0-pre.

@tarcieri

Copy link
Copy Markdown
Member Author

Sidebar: I think this sort of pattern might be interesting to adopt in der in the next breaking release

@tarcieri
tarcieri force-pushed the ssh-encoding/decoder-type branch from 4a5578d to 6c69af1 Compare November 10, 2026 16:03
Move nested decoding, length bounds, completion checks, and failure
state into a shared `Decoder<R>` type which owns the underlying reader.

This removes considerable complexity from the reader types, including
their individual `Reader::read_prefixed` implementations and the
supporting macro, leaving them responsible only for supplying bytes and
reporting the remaining length.

Nested decoding now uses a common `read_nested` implementation which
temporarily narrows the decoder's bounds. Each nesting level uses the
same `Decoder<R>` type, preserving `no_alloc` support without the
recursively nested generic reader types that previously caused
monomorphization bloat.

This is a breaking change: `Decode` implementations now accept
`&mut Decoder<impl Reader>`, which is slightly uglier from an API
perspective but enables a much better underlying implementation.

A blanket `From<R>` implementation keeps call sites concise by allowing
`Reader`s to be converted into a `Decoder` with `into()`..

We are also motivated by #615 to make another breaking `ssh-encoding`
release before the next ssh-key release: making the remaining infallible
`Mpint` conversions fallible would allow its size limits to be enforced
consistently.

Because this is a breaking change, the versions of `ssh-cipher`,
`ssh-derive`, and `ssh-encoding` have all been bumped to v0.4.0-pre.
@tarcieri
tarcieri force-pushed the ssh-encoding/decoder-type branch from 6c69af1 to db0299b Compare November 10, 2026 16:39
@tarcieri tarcieri changed the title [WIP] ssh-encoding: extract a shared Decoder<R> [BREAKING] ssh-encoding: extract a shared Decoder<R> [BREAKING] Nov 10, 2026
@tarcieri
tarcieri marked this pull request as ready for review November 10, 2026 16:39
@tarcieri
tarcieri merged commit da0af3d into master Nov 10, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant