phasm_core/stego/
error.rs1use core::fmt;
11
12#[derive(Debug)]
14pub enum StegoError {
15 InvalidJpeg(crate::jpeg::error::JpegError),
17 ImageTooSmall,
19 ImageTooLarge,
21 MessageTooLarge,
23 FrameCorrupted,
25 DecryptionFailed,
27 InvalidUtf8,
29 NoLuminanceChannel,
31 Cancelled,
33 KeyDerivationFailed,
35 DuplicatePassphrase,
37 ShadowEmbedFailed,
43 InvalidVideo(String),
45}
46
47impl fmt::Display for StegoError {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 Self::InvalidJpeg(e) => write!(f, "invalid JPEG: {e}"),
51 Self::ImageTooSmall => write!(f, "image too small for embedding"),
52 Self::ImageTooLarge => write!(f, "image too large (max 16384px / 200MP)"),
53 Self::MessageTooLarge => write!(f, "message too large for this image"),
54 Self::FrameCorrupted => write!(f, "payload frame CRC mismatch"),
55 Self::DecryptionFailed => write!(f, "decryption failed (wrong passphrase?)"),
56 Self::InvalidUtf8 => write!(f, "extracted text is not valid UTF-8"),
57 Self::NoLuminanceChannel => write!(f, "image has no luminance channel"),
58 Self::Cancelled => write!(f, "operation cancelled by user"),
59 Self::KeyDerivationFailed => write!(f, "key derivation failed"),
60 Self::DuplicatePassphrase => write!(f, "duplicate passphrase (each layer must use a unique passphrase)"),
61 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"),
62 Self::InvalidVideo(s) => write!(f, "invalid video: {s}"),
63 }
64 }
65}
66
67impl std::error::Error for StegoError {
68 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
69 match self {
70 Self::InvalidJpeg(e) => Some(e),
71 _ => None,
72 }
73 }
74}
75
76impl From<crate::jpeg::error::JpegError> for StegoError {
77 fn from(e: crate::jpeg::error::JpegError) -> Self {
78 Self::InvalidJpeg(e)
79 }
80}
81
82#[cfg(feature = "video")]
83impl From<crate::codec::h264::H264Error> for StegoError {
84 fn from(e: crate::codec::h264::H264Error) -> Self {
85 Self::InvalidVideo(e.to_string())
86 }
87}
88
89#[cfg(feature = "video")]
90impl From<crate::codec::mp4::Mp4Error> for StegoError {
91 fn from(e: crate::codec::mp4::Mp4Error) -> Self {
92 Self::InvalidVideo(e.to_string())
93 }
94}