Skip to main content

smb_server_proto/
error.rs

1//! Protocol error type shared by all codecs.
2
3use thiserror::Error;
4
5/// Errors produced while encoding or decoding SMB structures.
6#[derive(Debug, Error)]
7pub enum ProtoError {
8    /// Read or write past the end of the buffer.
9    #[error("buffer overrun (need {need} bytes at offset {at}, have {have})")]
10    Overrun {
11        /// Bytes required by the field being parsed.
12        need: usize,
13        /// Absolute offset inside the frame where parsing stopped.
14        at: usize,
15        /// Total bytes available.
16        have: usize,
17    },
18    /// A length, count or constant had an unexpected value.
19    #[error("invalid value in field '{field}'")]
20    InvalidField {
21        /// Name of the offending field.
22        field: &'static str,
23    },
24    /// A fixed magic marker did not match (e.g. `\xFFSMB`).
25    #[error("bad magic value")]
26    BadMagic,
27}