use core::fmt;
#[derive(Debug)]
pub enum StegoError {
InvalidJpeg(crate::jpeg::error::JpegError),
ImageTooSmall,
ImageTooLarge,
MessageTooLarge,
FrameCorrupted,
DecryptionFailed,
InvalidUtf8,
NoLuminanceChannel,
Cancelled,
KeyDerivationFailed,
DuplicatePassphrase,
ShadowEmbedFailed,
InvalidVideo(String),
}
impl fmt::Display for StegoError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidJpeg(e) => write!(f, "invalid JPEG: {e}"),
Self::ImageTooSmall => write!(f, "image too small for embedding"),
Self::ImageTooLarge => write!(f, "image too large (max 16384px / 200MP)"),
Self::MessageTooLarge => write!(f, "message too large for this image"),
Self::FrameCorrupted => write!(f, "payload frame CRC mismatch"),
Self::DecryptionFailed => write!(f, "decryption failed (wrong passphrase?)"),
Self::InvalidUtf8 => write!(f, "extracted text is not valid UTF-8"),
Self::NoLuminanceChannel => write!(f, "image has no luminance channel"),
Self::Cancelled => write!(f, "operation cancelled by user"),
Self::KeyDerivationFailed => write!(f, "key derivation failed"),
Self::DuplicatePassphrase => write!(f, "duplicate passphrase (each layer must use a unique passphrase)"),
Self::ShadowEmbedFailed => write!(f, "shadow embed failed: cascade exhausted at parity tier 128 — try a smaller primary message, different gop_size/quality, or different shadow passphrase"),
Self::InvalidVideo(s) => write!(f, "invalid video: {s}"),
}
}
}
impl std::error::Error for StegoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidJpeg(e) => Some(e),
_ => None,
}
}
}
impl From<crate::jpeg::error::JpegError> for StegoError {
fn from(e: crate::jpeg::error::JpegError) -> Self {
Self::InvalidJpeg(e)
}
}
#[cfg(feature = "video")]
impl From<crate::codec::h264::H264Error> for StegoError {
fn from(e: crate::codec::h264::H264Error) -> Self {
Self::InvalidVideo(e.to_string())
}
}
#[cfg(feature = "video")]
impl From<crate::codec::mp4::Mp4Error> for StegoError {
fn from(e: crate::codec::mp4::Mp4Error) -> Self {
Self::InvalidVideo(e.to_string())
}
}