visual_cryptography/
error.rs

1//! Error types for visual cryptography operations
2
3use std::{error::Error, fmt};
4
5/// Result type alias for visual cryptography operations
6pub type Result<T> = std::result::Result<T, VCError>;
7
8/// Error types for visual cryptography operations
9#[derive(Debug)]
10pub enum VCError {
11    /// Invalid configuration provided
12    InvalidConfiguration(String),
13    /// Insufficient shares to decrypt
14    InsufficientShares { required: usize, provided: usize },
15    /// Error during decryption
16    DecryptionError(String),
17    /// Error related to cover images
18    CoverImageError(String),
19    /// Image processing error
20    ImageError(String),
21    /// Matrix operation error
22    MatrixError(String),
23    /// QR code generation or processing error
24    QrCodeError(String),
25}
26
27impl fmt::Display for VCError {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            VCError::InvalidConfiguration(msg) => write!(f, "Invalid configuration: {}", msg),
31            VCError::InsufficientShares { required, provided } => {
32                write!(
33                    f,
34                    "Insufficient shares: required {}, provided {}",
35                    required, provided
36                )
37            }
38            VCError::DecryptionError(msg) => write!(f, "Decryption error: {}", msg),
39            VCError::CoverImageError(msg) => write!(f, "Cover image error: {}", msg),
40            VCError::ImageError(msg) => write!(f, "Image error: {}", msg),
41            VCError::MatrixError(msg) => write!(f, "Matrix error: {}", msg),
42            VCError::QrCodeError(msg) => write!(f, "QR code error: {}", msg),
43        }
44    }
45}
46
47impl Error for VCError {}
48
49impl From<image::ImageError> for VCError {
50    fn from(err: image::ImageError) -> Self {
51        VCError::ImageError(err.to_string())
52    }
53}