argon2_kdf/error.rs
1use std::fmt;
2
3/// Errors that may occur when using this crate
4#[derive(Debug)]
5pub enum Argon2Error {
6 /// Indicates that the user of a type or function has specified an invalid parameter or
7 /// set of parameters
8 InvalidParameter(&'static str),
9
10 /// Indicates that a provided hash was expected to be valid, but is invalid. This
11 /// normally occurs when a hash is improperly formatted.
12 InvalidHash(&'static str),
13
14 /// An error that is unhandled by the crate, but is recognized by the C argon2 library
15 CLibError(String),
16}
17
18impl std::error::Error for Argon2Error {}
19
20impl fmt::Display for Argon2Error {
21 /// Turn an `Argon2Error` into a descriptive string
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Argon2Error::InvalidParameter(msg) => {
25 write!(f, "Argon2Error: Invalid parameter: {}", msg)
26 }
27 Argon2Error::InvalidHash(msg) => write!(f, "Argon2Error: Invalid hash: {}", msg),
28 Argon2Error::CLibError(msg) => {
29 write!(f, "Argon2Error: Error from C library: {}", msg)
30 }
31 }
32 }
33}