trelent_hyok/error/encryption.rs
1//! Error types related to encryption and decryption operations.
2//!
3//! This module provides error types that may occur during data encryption
4//! and decryption operations, including key validation, algorithm-specific
5//! errors, and data formatting issues.
6
7use core::fmt;
8use std::fmt::Debug;
9
10/// Represents an error encountered during encryption or decryption operations.
11///
12/// This error type is used when encryption-related operations fail, such as:
13/// - Invalid key size or format
14/// - Algorithm-specific failures
15/// - Data padding issues
16/// - Authentication failures
17#[derive(Debug, Eq, PartialEq)]
18pub struct EncryptionError(pub String);
19
20impl EncryptionError {
21 /// Creates a new encryption error with the specified message.
22 ///
23 /// # Arguments
24 /// * `message` - A description of the error that occurred
25 pub fn new(message: String) -> Self {
26 Self(message)
27 }
28}
29
30impl fmt::Display for EncryptionError {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 write!(f, "Error Encrypting: {}", self.0)
33 }
34}