sare_core/kdf/
error.rs

1use std::fmt;
2
3use hkdf::InvalidLength;
4use scrypt::errors::InvalidOutputLen;
5use scrypt::errors::InvalidParams;
6
7#[derive(Debug)]
8pub enum KDFError {
9    InvalidKeyLength,
10    InvalidOutputLength,
11    InvalidParams,
12    Unexpected,
13}
14
15impl fmt::Display for KDFError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            KDFError::InvalidKeyLength => write!(f, "Invalid key length"),
19            KDFError::InvalidOutputLength => write!(f, "Invalid output length"),
20            KDFError::InvalidParams => write!(f, "Invalid parameters"),
21            KDFError::Unexpected => write!(f, "Unexpected error"),
22        }
23    }
24}
25
26impl From<InvalidLength> for KDFError {
27    fn from(_: InvalidLength) -> Self {
28        KDFError::InvalidKeyLength
29    }
30}
31
32impl From<InvalidOutputLen> for KDFError {
33    fn from(_: InvalidOutputLen) -> Self {
34        KDFError::InvalidOutputLength
35    }
36}
37
38impl From<InvalidParams> for KDFError {
39    fn from(_: InvalidParams) -> Self {
40        KDFError::InvalidParams
41    }
42}