smb_server/encrypted/
error.rs1use thiserror::Error;
4
5use crate::error::SmbError;
6
7#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum EncryptionError {
12 #[error("invalid setting `{setting}`")]
15 InvalidSetting { setting: &'static str },
16 #[error("setting `{setting}` differs from the share's")]
19 SettingMismatch { setting: &'static str },
20 #[error("the key does not match the share")]
25 KeyMismatch,
26 #[error("the share has entries and no marker")]
30 MarkerMissing,
31 #[error("the marker is not valid")]
38 MarkerInvalid,
39 #[error("format version {version} is not supported")]
41 UnsupportedFormat { version: u8 },
42 #[error("the inner backend failed")]
44 Backend(#[source] SmbError),
45 #[error("the random generator failed")]
47 Random(#[source] getrandom::Error),
48}
49
50#[cfg(test)]
51mod tests {
52 use std::error::Error;
53
54 use super::*;
55
56 #[test]
57 fn display_texts() {
58 assert_eq!(
59 EncryptionError::InvalidSetting {
60 setting: "block_size"
61 }
62 .to_string(),
63 "invalid setting `block_size`"
64 );
65 assert_eq!(
66 EncryptionError::SettingMismatch {
67 setting: "encrypt_names"
68 }
69 .to_string(),
70 "setting `encrypt_names` differs from the share's"
71 );
72 assert_eq!(
73 EncryptionError::UnsupportedFormat { version: 7 }.to_string(),
74 "format version 7 is not supported"
75 );
76 assert_eq!(
77 EncryptionError::Backend(SmbError::DiskFull).to_string(),
78 "the inner backend failed"
79 );
80 assert_eq!(
81 EncryptionError::Random(getrandom::Error::UNEXPECTED).to_string(),
82 "the random generator failed"
83 );
84 }
85
86 #[test]
87 fn backend_and_random_errors_are_sources() {
88 let backend = EncryptionError::Backend(SmbError::DiskFull);
89 assert_eq!(backend.source().unwrap().to_string(), "disk full");
90
91 let random = EncryptionError::Random(getrandom::Error::UNEXPECTED);
92 assert!(random.source().is_some(), "the random error has a source");
93 }
94}