From f0441f7e014894516615542258feb803f9ac7d35 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Sat, 18 May 2024 08:32:48 -0400 Subject: [PATCH] Implement `AsRef<[u8]>` and `into_bytes(self)` for `Unparsed` Add conversion methods to gain access to the inner bytes of `Unparsed`, per discussion in https://github.com/wiktor-k/ssh-agent-lib/pull/72 Signed-off-by: Ross Williams --- src/proto/message/unparsed.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/proto/message/unparsed.rs b/src/proto/message/unparsed.rs index a88f062..74c477f 100644 --- a/src/proto/message/unparsed.rs +++ b/src/proto/message/unparsed.rs @@ -16,6 +16,11 @@ impl Unparsed { let mut v = &self.0[..]; T::decode(&mut v) } + + /// Obtain the unparsed bytes as a `Vec`, consuming the `Unparsed` + pub fn into_bytes(self) -> Vec { + self.0 + } } impl From> for Unparsed { @@ -24,6 +29,12 @@ impl From> for Unparsed { } } +impl AsRef<[u8]> for Unparsed { + fn as_ref(&self) -> &[u8] { + self.0.as_ref() + } +} + impl Encode for Unparsed { fn encoded_len(&self) -> ssh_encoding::Result { Ok(self.0.len())