sftp_protocol/packet/
symlink.rs

1use camino::Utf8PathBuf;
2
3use super::kind::PacketType;
4use super::PayloadTrait;
5
6#[derive(Debug, Eq, PartialEq, Nom, Serialize)]
7#[nom(BigEndian)]
8#[cfg_attr(test, derive(test_strategy::Arbitrary))]
9pub struct Symlink {
10	pub id: u32,
11	#[nom(Parse(crate::util::parse_path))]
12	#[serde(serialize_with = "crate::util::path_with_u32_length")]
13	pub linkpath: Utf8PathBuf,
14	#[nom(Parse(crate::util::parse_path))]
15	#[serde(serialize_with = "crate::util::path_with_u32_length")]
16	pub targetpath: Utf8PathBuf
17}
18
19impl PayloadTrait for Symlink {
20	const Type: PacketType = PacketType::Symlink;
21	fn binsize(&self) -> u32 {
22		4 + (4 + self.linkpath.as_str().len() as u32) + (4 + self.targetpath.as_str().len() as u32)
23	}
24}
25
26impl From<Symlink> for super::Payload {
27	fn from(p: Symlink) -> Self {
28		Self::Symlink(p)
29	}
30}
31
32#[cfg(test)]
33mod tests {
34	use test_strategy::proptest;
35	use crate::parser::encode;
36	use crate::parser::Parser;
37	use super::*;
38
39	#[proptest]
40	fn roundtrip_whole(input: Symlink) {
41		let mut stream = Parser::default();
42		let packet = input.into_packet();
43		stream.write(&encode(&packet)).unwrap();
44		assert_eq!(stream.get_packet(), Ok(Some(packet)));
45		assert_eq!(stream.get_packet(), Ok(None));
46	}
47}
48