ev3_runner/
protocol.rs

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