1use alloc::string::ToString;
4use core::fmt;
5
6#[derive(Clone, Copy, Eq, PartialEq)]
11pub struct ParseError(password_hash::Error);
12
13impl ParseError {
14 pub(crate) fn new(err: password_hash::Error) -> Self {
16 Self(err)
17 }
18}
19
20impl fmt::Debug for ParseError {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 f.debug_tuple("ParseError")
23 .field(&self.0.to_string())
24 .finish()
25 }
26}
27
28impl fmt::Display for ParseError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 write!(f, "{}", &self.0)
31 }
32}
33
34#[derive(Clone, Copy, Debug, Eq, PartialEq)]
36pub enum VerifyError {
37 Parse(ParseError),
39
40 PasswordInvalid,
42}
43
44impl fmt::Display for VerifyError {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 Self::Parse(err) => write!(f, "{err}"),
48 Self::PasswordInvalid => write!(f, "password is invalid"),
49 }
50 }
51}
52
53impl From<ParseError> for VerifyError {
54 fn from(err: ParseError) -> VerifyError {
55 VerifyError::Parse(err)
56 }
57}
58
59#[cfg(feature = "std")]
60impl std::error::Error for ParseError {}
61
62#[cfg(feature = "std")]
63impl std::error::Error for VerifyError {}