sftp_protocol/packet/
status.rs1use super::kind::PacketType;
2use super::PayloadTrait;
3
4#[derive(Debug, Eq, PartialEq, Nom, Serialize)]
5#[nom(BigEndian)]
6#[cfg_attr(test, derive(test_strategy::Arbitrary))]
7pub struct Status {
8 pub id: u32,
9 pub status: StatusType,
10 #[nom(Parse(crate::util::parse_string))]
12 #[serde(serialize_with = "crate::util::str_with_u32_length")]
13 pub message: String,
14 #[nom(Parse(crate::util::parse_string))]
15 #[serde(serialize_with = "crate::util::str_with_u32_length")]
16 pub language: String
17}
18
19impl PayloadTrait for Status {
20 const Type: PacketType = PacketType::Status;
21 fn binsize(&self) -> u32 {
22 4 + 4 + (4 + self.message.len() as u32) + (4 + self.language.len() as u32)
23 }
24}
25
26impl From<Status> for super::Payload {
27 fn from(p: Status) -> Self {
28 Self::Status(p)
29 }
30}
31
32#[derive(Clone, Copy, Debug, Eq, PartialEq, Nom, Serialize_repr)]
33#[repr(u32)]
34#[cfg_attr(test, derive(test_strategy::Arbitrary))]
35pub enum StatusType {
36 OK = 0,
37 EOF = 1,
38 NoSuchFile = 2,
39 PermissionDenied = 3,
40 Failure = 4,
41 BadMessage = 5,
42 NoConnection = 6,
43 ConnectionLost = 7,
44 OpUnsupported = 8
45}
46
47#[cfg(test)]
48mod tests {
49 use test_strategy::proptest;
50 use crate::parser::encode;
51 use crate::parser::Parser;
52 use super::*;
53
54 #[proptest]
55 fn roundtrip_whole(input: Status) {
56 let mut stream = Parser::default();
57 let packet = input.into_packet();
58 stream.write(&encode(&packet)).unwrap();
59 assert_eq!(stream.get_packet(), Ok(Some(packet)));
60 assert_eq!(stream.get_packet(), Ok(None));
61 }
62}
63