use core::fmt::{Display, Formatter, Result};
use std::error::Error;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum AttrkeyError {
AttributesTooFew,
SaltsTooFew,
SaltsTooMany,
PwdHasherFail,
HashOutputAbsent,
ConstraintTooSmall,
IndicesTooFew,
IndicesTooMany,
IndexOutOfBounds,
Annihilation,
SeedTooLong,
}
impl Display for AttrkeyError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.write_str(match self {
Self::AttributesTooFew => "not enough attributes",
Self::SaltsTooFew => "too few provided salts",
Self::SaltsTooMany => "too many provided salts",
Self::PwdHasherFail => "password hashing failed",
Self::HashOutputAbsent => "password hash contained no output",
Self::ConstraintTooSmall => "constraint is too small",
Self::IndicesTooFew => "too few selected attributes",
Self::IndicesTooMany => "too many selected attributes",
Self::IndexOutOfBounds => "out of bound selection index",
Self::Annihilation => "key pair annihilation failed",
Self::SeedTooLong => "seed length exceeds HKDF output limit",
})
}
}
impl Error for AttrkeyError {}
#[test]
fn test_display() {
assert_eq!(
AttrkeyError::AttributesTooFew.to_string(),
"not enough attributes"
);
assert_eq!(
AttrkeyError::SaltsTooFew.to_string(),
"too few provided salts"
);
assert_eq!(
AttrkeyError::SaltsTooMany.to_string(),
"too many provided salts"
);
assert_eq!(
AttrkeyError::PwdHasherFail.to_string(),
"password hashing failed"
);
assert_eq!(
AttrkeyError::HashOutputAbsent.to_string(),
"password hash contained no output"
);
assert_eq!(
AttrkeyError::ConstraintTooSmall.to_string(),
"constraint is too small"
);
assert_eq!(
AttrkeyError::IndicesTooFew.to_string(),
"too few selected attributes"
);
assert_eq!(
AttrkeyError::IndicesTooMany.to_string(),
"too many selected attributes"
);
assert_eq!(
AttrkeyError::IndexOutOfBounds.to_string(),
"out of bound selection index"
);
assert_eq!(
AttrkeyError::Annihilation.to_string(),
"key pair annihilation failed"
);
assert_eq!(
AttrkeyError::SeedTooLong.to_string(),
"seed length exceeds HKDF output limit"
);
}