1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use failure::Fail;
use std::result;

/// Result that encapsulates the Error type of this library
pub type Result<T> = result::Result<T, Error>;

/// Error raised by the routines of this library
#[derive(Fail, Clone, Debug, PartialEq)]
pub enum Error {
    /// Error while decrypting the data
    #[fail(display = "DecryptionError: {}", _0)]
    DecryptionError(String),

    /// Data is encrypted with an unsupported crypto algorithm
    #[fail(display = "UnsupportedAlgorithm: {}", _0)]
    UnsupportedAlgorithm(i32),

    /// Invalid key
    #[fail(
        display = "Invalid key: Only hexadecimal characters are allowed [1234567890abcdefABCDEF]"
    )]
    InvalidKeyCharset,

    /// Invalid key
    #[fail(display = "Invalid key: Length should be {}", _0)]
    InvalidKeyLength(usize),
}