sftp-protocol 0.1.0

A pure Rust implementation of the SFTP protocol
Documentation
use super::kind::PacketType;
use super::PayloadTrait;

#[derive(Debug, Eq, PartialEq, Nom, Serialize)]
#[nom(BigEndian)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub struct Close {
	pub id: u32,
	#[nom(Parse(crate::util::parse_uuid))]
	#[serde(serialize_with = "crate::util::serialize_uuid")]
	#[cfg_attr(test, strategy(crate::util::arbitrary_uuid()))]
	pub handle: uuid::Uuid
}

impl PayloadTrait for Close {
	const Type: PacketType = PacketType::Close;
	fn binsize(&self) -> u32 {
		4 + 4 + 36
	}
}

impl From<Close> for super::Payload {
	fn from(p: Close) -> Self {
		Self::Close(p)
	}
}

#[cfg(test)]
mod tests {
	use test_strategy::proptest;
	use crate::parser::encode;
	use crate::parser::Parser;
	use super::*;

	#[proptest]
	fn roundtrip_whole(input: Close) {
		let mut stream = Parser::default();
		let packet = input.into_packet();
		stream.write(&encode(&packet)).unwrap();
		assert_eq!(stream.get_packet(), Ok(Some(packet)));
		assert_eq!(stream.get_packet(), Ok(None));
	}
}