Skip to content

Commit 88c8022

Browse files
committed
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 `<Extension as Encode>::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 <ross@ross-williams.net>
1 parent 1224627 commit 88c8022

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/proto/message.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,7 @@ impl Encode for Extension {
622622

623623
fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
624624
self.name.encode(writer)?;
625-
626-
// NOTE: extension messages do not contain a length,
627-
// as the inner Vec<u8> will be encoded with it's own length.
628-
writer.write(&self.details.0[..])?;
625+
self.details.encode(writer)?;
629626
Ok(())
630627
}
631628
}
@@ -657,7 +654,12 @@ impl Encode for Unparsed {
657654
}
658655

659656
fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
660-
self.0.encode(writer)
657+
// NOTE: Unparsed fields do not embed a length u32,
658+
// as the inner Vec<u8> encoding is implementation-defined
659+
// (usually an Extension)
660+
writer.write(&self.0[..])?;
661+
662+
Ok(())
661663
}
662664
}
663665

0 commit comments

Comments
 (0)