ssh-encoding 0.4.0-rc.1

Pure Rust implementation of SSH data type decoders/encoders as described in RFC4251
Documentation

RustCrypto: SSH Encoding

crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat

Documentation

About

Pure Rust implementation of SSH data type decoders/encoders as described in RFC4251.

Decoding

Convert a reader into a Decoder to start decoding SSH data types:

use ssh_encoding::{Decode, Reader};

let mut decoder = [0, 0, 0, 4, 0, 0, 0, 42]
    .as_slice()
    .into_decoder()
    .expect("input too long");
let value = decoder.read_prefixed(u32::decode).expect("invalid u32");
assert_eq!(decoder.finish(value).expect("remaining data"), 42);

Reader supplies bytes and their remaining length. Decoder<R> owns the reader and handles nested bounds, complete consumption, and failure state. Nested callbacks use the same decoder type and store enclosing bounds on the call stack without allocation. Decode implementations accept &mut Decoder<impl Reader>.

Construct a decoder with Decoder::new(reader) or reader.into_decoder(). Both return an error if the remaining binary input exceeds 128 MiB, matching OpenSSH's hard buffer limit. Decoder::read_prefixed checks that the declared body fits in the remaining bytes of the current scope before decoding it.

Raw byte slices implement Reader. With the corresponding features enabled, Base64Reader decodes Base64 incrementally, and DecodePem wraps a PEM reader in the same decoder internally.

For Base64 and PEM, the limit applies to the decoded binary length. Applications must separately bound textual input and file reads before constructing a reader.

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.