openssh_sftp_protocol_error/response_error.rs
1use std::fmt;
2
3use serde::Deserialize;
4use vec_strings::TwoStrs;
5
6#[derive(Debug, Copy, Clone)]
7#[non_exhaustive]
8pub enum ErrorCode {
9 /// is returned when a reference is made to a file which should exist
10 /// but doesn't.
11 NoSuchFile,
12
13 /// Returned when the authenticated user does not have sufficient
14 /// permissions to perform the operation.
15 PermDenied,
16
17 /// A generic catch-all error message.
18 ///
19 /// It should be returned if an error occurs for which there is no more
20 /// specific error code defined.
21 Failure,
22
23 /// May be returned if a badly formatted packet or protocol
24 /// incompatibility is detected.
25 ///
26 /// If the handle is opened read only, but write flag is required,
27 /// then `BadMessage` might be returned, vice versa.
28 BadMessage,
29
30 /// Indicates that an attempt was made to perform an operation which
31 /// is not supported for the server.
32 OpUnsupported,
33
34 /// Unknown error code
35 Unknown,
36}
37
38#[derive(Clone, Deserialize)]
39pub struct ErrMsg(TwoStrs);
40
41impl ErrMsg {
42 /// Returns (err_message, language_tag).
43 ///
44 /// Language tag is defined according to specification [RFC-1766].
45 ///
46 /// It can be parsed by
47 /// [pyfisch/rust-language-tags](https://github.com/pyfisch/rust-language-tags)
48 /// according to
49 /// [this issue](https://github.com/pyfisch/rust-language-tags/issues/39).
50 pub fn get(&self) -> (&str, &str) {
51 self.0.get()
52 }
53}
54
55impl fmt::Display for ErrMsg {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 let (err_msg, language_tag) = self.get();
58 write!(
59 f,
60 "Err Message: {}, Language Tag: {}",
61 err_msg, language_tag
62 )
63 }
64}
65
66impl fmt::Debug for ErrMsg {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 fmt::Display::fmt(self, f)
69 }
70}