1use binrw::prelude::*;
4
5use smb_dtyp::binrw_util::prelude::*;
6
7#[binrw::binrw]
8#[derive(Debug, PartialEq, Eq)]
9pub struct ErrorResponse {
10 #[bw(calc = 9)]
11 #[br(assert(_structure_size == 9))]
12 _structure_size: u16,
13
14 #[bw(try_calc = error_data.len().try_into())]
15 _error_context_count: u8,
16
17 #[br(assert(_reserved == 0))]
18 #[bw(calc = 0)]
19 _reserved: u8,
20
21 #[bw(calc = PosMarker::default())]
22 _byte_count: PosMarker<u32>,
23
24 #[br(count = _error_context_count)]
25 pub error_data: Vec<ErrorResponseContext>,
26}
27
28#[binrw::binrw]
29#[derive(Debug, PartialEq, Eq)]
30pub struct ErrorResponseContext {
31 #[brw(align_before = 8)]
35 #[bw(try_calc = error_data.len().try_into())]
36 _error_data_length: u32,
37 pub error_id: ErrorId,
38 #[br(count = _error_data_length)]
39 pub error_data: Vec<u8>,
40}
41
42#[binrw::binrw]
43#[derive(Debug, PartialEq, Eq)]
44#[brw(repr(u32))]
45pub enum ErrorId {
46 Default = 0,
47 ShareRedirect = 0x72645253,
48}
49
50#[cfg(test)]
51mod tests {
52 use crate::*;
53
54 use super::*;
55
56 #[test]
57 pub fn test_simple_error_pasrsed() {
58 let msg = decode_content(&[
59 0xfe, 0x53, 0x4d, 0x42, 0x40, 0x0, 0x1, 0x0, 0x34, 0x0, 0x0, 0xc0, 0x5, 0x0, 0x1, 0x0,
60 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
61 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x71, 0x0, 0x0, 0x28, 0x0, 0x30, 0x0, 0x0, 0xf7,
62 0xd, 0xa6, 0x1d, 0x9b, 0x2c, 0x43, 0xd3, 0x26, 0x88, 0x74, 0xf, 0xdf, 0x47, 0x59, 0x24,
63 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
64 ]);
65 assert_eq!(msg.header.status, Status::ObjectNameNotFound as u32);
66 let msg = match msg.content {
67 ResponseContent::Error(msg) => msg,
68 _ => panic!("Unexpected response"),
69 };
70 assert_eq!(msg, ErrorResponse { error_data: vec![] })
71 }
72}