Skip to main content

capsid_protocol/
error.rs

1use crate::digest::DigestError;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    #[error("{0}")]
6    Invalid(&'static str),
7
8    #[error("invalid digest")]
9    Digest(#[from] DigestError),
10
11    #[error("invalid boot configuration encoding")]
12    BootEncoding(#[from] base64::DecodeError),
13
14    #[error("invalid protocol JSON")]
15    Json(#[from] serde_json::Error),
16
17    #[error("guest rejected the forwarding handshake")]
18    Rejected,
19
20    #[error("invalid frame length")]
21    FrameLength,
22
23    #[error("frame exceeds protocol limit")]
24    FrameSize,
25
26    #[error("input exceeds {max} bytes")]
27    InputSize { max: u64 },
28
29    #[error("oversized TCP data frame")]
30    DataFrameSize,
31
32    #[error("invalid TCP completion receipt")]
33    Receipt,
34}
35
36impl Error {
37    // Every failure but a refused handshake describes bad input from a peer or
38    // a caller; a guest that refuses a forward is an internal fault.
39    pub fn is_invalid_input(&self) -> bool {
40        !matches!(self, Self::Rejected)
41    }
42}
43
44pub type Result<T, E = Error> = std::result::Result<T, E>;