1use bincode::{Decode, Encode};
2use std::{fmt::Debug, path::PathBuf};
3
4#[derive(Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone)]
5pub struct VersionHeader(pub String);
6
7#[derive(Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone)]
8pub struct VersionResponse(pub VersionStatus);
9
10#[derive(Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone)]
11pub enum VersionStatus {
12 Match,
13 Mismatch(String),
14}
15
16#[derive(Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone)]
17pub struct Request {
18 pub action: Action,
19 pub path: PathBuf,
20 pub hash: u64,
21 pub password: [u8; 32],
22}
23
24impl Debug for Request {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 f.debug_struct("Request")
27 .field("action", &self.action)
28 .field("path", &self.path)
29 .field("hash", &self.hash)
30 .field("password", &"REDACTED")
31 .finish()
32 }
33}
34
35#[derive(Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
36pub enum Action {
37 Upload,
38 Run(bool),
39}
40
41#[derive(Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
42pub struct Validation {
43 pub password: MatchStatus,
44 pub hash: MatchStatus,
45 pub path: PathStatus,
46}
47
48impl Default for Validation {
49 fn default() -> Self {
50 Self {
51 password: MatchStatus::Mismatch,
52 hash: MatchStatus::Mismatch,
53 path: PathStatus::Valid,
54 }
55 }
56}
57
58#[derive(Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
59pub enum MatchStatus {
60 Match,
61 Mismatch,
62}
63
64#[derive(Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, thiserror::Error)]
65pub enum PathStatus {
66 #[error("Path is valid. This isn't an error")]
67 Valid,
68 #[error("Path contains invalid components (e.g., '..')")]
69 InvalidComponents,
70 #[error("Path is absolute, only relative paths allowed")]
71 AbsolutePath,
72 #[error("Path would escape working directory")]
73 EscapesWorkingDir,
74 #[error("Failed to canonicalize path")]
75 CanonicalizationFailed,
76}