capsid-protocol 0.1.0-alpha.1

Versioned, size-bounded messages between the Capsid host and its guest agent.
Documentation
use crate::digest::DigestError;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("{0}")]
    Invalid(&'static str),

    #[error("invalid digest")]
    Digest(#[from] DigestError),

    #[error("invalid boot configuration encoding")]
    BootEncoding(#[from] base64::DecodeError),

    #[error("invalid protocol JSON")]
    Json(#[from] serde_json::Error),

    #[error("guest rejected the forwarding handshake")]
    Rejected,

    #[error("invalid frame length")]
    FrameLength,

    #[error("frame exceeds protocol limit")]
    FrameSize,

    #[error("input exceeds {max} bytes")]
    InputSize { max: u64 },

    #[error("oversized TCP data frame")]
    DataFrameSize,

    #[error("invalid TCP completion receipt")]
    Receipt,
}

impl Error {
    // Every failure but a refused handshake describes bad input from a peer or
    // a caller; a guest that refuses a forward is an internal fault.
    pub fn is_invalid_input(&self) -> bool {
        !matches!(self, Self::Rejected)
    }
}

pub type Result<T, E = Error> = std::result::Result<T, E>;