From 88c80229bf5bf10a96167f69e415e9861092bb75 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Tue, 7 May 2024 12:44:19 -0400 Subject: [PATCH] Specialize extension payload encoding in Unparsed Extension payload, after the RFC4251-encoded name string, is an opaque blob, not an RFC4251 array of bytes, so it MUST NOT have a u32 length header. This had been handled in the `::encode` implementation, but that led to a bug in which there was a mismatch between the number of bytes written and the length calculated. This commit consolidates all the special-case handling of the opaque blob into `impl Encode for Unparsed`. Any messages (i.e. Extension) that contain `Unparsed` fields can now just call `encoded_len()` and `encode()` like for any other field type. Signed-off-by: Ross Williams --- src/proto/message.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/proto/message.rs b/src/proto/message.rs index 848cd3f..7651d5e 100644 --- a/src/proto/message.rs +++ b/src/proto/message.rs @@ -622,10 +622,7 @@ impl Encode for Extension { fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> { self.name.encode(writer)?; - - // NOTE: extension messages do not contain a length, - // as the inner Vec will be encoded with it's own length. - writer.write(&self.details.0[..])?; + self.details.encode(writer)?; Ok(()) } } @@ -657,7 +654,12 @@ impl Encode for Unparsed { } fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> { - self.0.encode(writer) + // NOTE: Unparsed fields do not embed a length u32, + // as the inner Vec encoding is implementation-defined + // (usually an Extension) + writer.write(&self.0[..])?; + + Ok(()) } }