image4 0.8.2

A no_std-friendly library for parsing and generation of Image4 images written in pure Rust.
Documentation
use core::fmt;

/// An error that may occur while signing an Image4 manifest.
#[derive(Debug)]
#[non_exhaustive]
pub enum SigningError {
    /// A cryptographic error occurred while generating a signature.
    Signature(signature::Error),
    /// Failed to encode the generated signature.
    Encoding(der::Error),
}

impl fmt::Display for SigningError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            SigningError::Signature(e) => fmt::Display::fmt(e, f),
            SigningError::Encoding(e) => write!(f, "failed to encode manifest signature: {e}"),
        }
    }
}

impl From<signature::Error> for SigningError {
    fn from(value: signature::Error) -> Self {
        Self::Signature(value)
    }
}

impl From<der::Error> for SigningError {
    fn from(value: der::Error) -> Self {
        Self::Encoding(value)
    }
}

#[cfg(feature = "std")]
impl std::error::Error for SigningError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        Some(match self {
            SigningError::Signature(e) => e,
            SigningError::Encoding(e) => e,
        })
    }
}