1use core::fmt;
4
5pub type Result<T> = core::result::Result<T, Error>;
7
8#[derive(Copy, Clone, Debug, Eq, PartialEq)]
10#[non_exhaustive]
11pub enum Error {
12 Algorithm,
14
15 Crypto,
17
18 EncodingInvalid,
20
21 OutOfMemory,
23
24 OutputSize,
26
27 ParamInvalid {
29 name: &'static str,
31 },
32
33 ParamsInvalid,
35
36 PasswordInvalid,
38
39 SaltInvalid,
41
42 Version,
44}
45
46impl fmt::Display for Error {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> core::result::Result<(), fmt::Error> {
48 match self {
49 Self::Algorithm => write!(f, "unsupported algorithm"),
50 Self::Crypto => write!(f, "cryptographic error"),
51 Self::EncodingInvalid => write!(f, "invalid encoding"),
52 Self::OutOfMemory => write!(f, "out of memory"),
53 Self::OutputSize => write!(f, "password hash output size invalid"),
54 Self::ParamInvalid { name } => write!(f, "invalid parameter: {name:?}"),
55 Self::ParamsInvalid => write!(f, "invalid parameters"),
56 Self::PasswordInvalid => write!(f, "invalid password"),
57 Self::SaltInvalid => write!(f, "invalid salt"),
58 Self::Version => write!(f, "invalid algorithm version"),
59 }
60 }
61}
62
63impl core::error::Error for Error {}