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
28
29
//! Errors for KBKDF crate

use std::fmt::Formatter;

/// Errors returned by the KBKDF function
#[derive(Debug)]
pub enum Error {
    /// Derived key length is invalid
    InvalidDerivedKeyLen,
    /// Provided buffer is of invalid size
    InvalidBufferLength(String),
    /// Error with implementation
    ImplementationError(String),
    /// Invalid key size
    InvalidKeySize(String),
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::InvalidDerivedKeyLen => write!(f, "Derived key length is invalid"),
            Error::InvalidBufferLength(e) => write!(f, "Invalid output buffer provided: {}", e),
            Error::ImplementationError(e) => write!(f, "{}", e),
            Error::InvalidKeySize(e) => write!(f, "Invalid key size provided: {}", e),
        }
    }
}

impl std::error::Error for Error {}