ssh_agent_lib/proto/message/
unparsed.rs1use ssh_encoding::{self, Decode, Encode, Writer};
4
5#[derive(Debug, PartialEq, Clone)]
8pub struct Unparsed(Vec<u8>);
9
10impl Unparsed {
11 pub fn parse<T>(&self) -> std::result::Result<T, <T as Decode>::Error>
13 where
14 T: Decode,
15 {
16 let mut v = &self.0[..];
17 T::decode(&mut v)
18 }
19
20 pub fn into_bytes(self) -> Vec<u8> {
22 self.0
23 }
24}
25
26impl From<Vec<u8>> for Unparsed {
27 fn from(value: Vec<u8>) -> Self {
28 Self(value)
29 }
30}
31
32impl AsRef<[u8]> for Unparsed {
33 fn as_ref(&self) -> &[u8] {
34 self.0.as_ref()
35 }
36}
37
38impl Encode for Unparsed {
39 fn encoded_len(&self) -> ssh_encoding::Result<usize> {
40 Ok(self.0.len())
41 }
42
43 fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
44 writer.write(&self.0[..])?;
48
49 Ok(())
50 }
51}