spacedls 0.4.0

no_std CCSDS 355.0-B-2 (SDLS) Space Data Link Security implementation
Documentation
use super::managed_key::KeyState;
use super::managed_sa::SaState;
use core::fmt;

/// Errors from [`ManagedKey`](crate::key::ManagedKey) lifecycle operations.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KeyManagementError {
    NotActive,
    NotFound,
    InvalidTransition { from: KeyState, to: KeyState },
}

impl fmt::Display for KeyManagementError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NotActive => write!(f, "key not active"),
            Self::NotFound => write!(f, "key not found"),
            Self::InvalidTransition { from, to } => {
                write!(f, "invalid key transition: {from:?} -> {to:?}")
            }
        }
    }
}

impl core::error::Error for KeyManagementError {}

/// Errors from [`ManagedSa`](crate::protocol::ManagedSa) lifecycle operations.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SaManagementError {
    NotOperational,
    InvalidTransition { from: SaState, to: SaState },
    NotFound,
}

impl fmt::Display for SaManagementError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::NotOperational => write!(f, "SA not operational"),
            Self::InvalidTransition { from, to } => {
                write!(f, "invalid SA transition: {from:?} -> {to:?}")
            }
            Self::NotFound => write!(f, "SA not found"),
        }
    }
}

impl core::error::Error for SaManagementError {}