use core::fmt::{Display, Formatter, Result};
use std::error::Error;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ArrkeyError {
AttributesTooFew,
MemoryTooSmall,
TimeTooSmall,
ThreadsTooFew,
ThreadsTooMany,
ConstraintTooSmall,
HardenFail,
IndicesTooFew,
IndicesTooMany,
IndexOutOfBounds,
Annihilation,
}
impl Display for ArrkeyError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.write_str(match self {
Self::AttributesTooFew => "not enough attributes",
Self::MemoryTooSmall => "memory cost is too small",
Self::TimeTooSmall => "time cost is too small",
Self::ThreadsTooFew => "not enough threads",
Self::ThreadsTooMany => "too many threads",
Self::ConstraintTooSmall => "constraint is too small",
Self::HardenFail => "failed to harden attributes",
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",
})
}
}
impl Error for ArrkeyError {}
#[test]
fn test_display() {
assert_eq!(
ArrkeyError::AttributesTooFew.to_string(),
"not enough attributes"
);
assert_eq!(
ArrkeyError::MemoryTooSmall.to_string(),
"memory cost is too small"
);
assert_eq!(
ArrkeyError::TimeTooSmall.to_string(),
"time cost is too small"
);
assert_eq!(ArrkeyError::ThreadsTooFew.to_string(), "not enough threads");
assert_eq!(ArrkeyError::ThreadsTooMany.to_string(), "too many threads");
assert_eq!(
ArrkeyError::ConstraintTooSmall.to_string(),
"constraint is too small"
);
assert_eq!(
ArrkeyError::HardenFail.to_string(),
"failed to harden attributes"
);
assert_eq!(
ArrkeyError::IndicesTooFew.to_string(),
"too few selected attributes"
);
assert_eq!(
ArrkeyError::IndicesTooMany.to_string(),
"too many selected attributes"
);
assert_eq!(
ArrkeyError::IndexOutOfBounds.to_string(),
"out of bound selection index"
);
assert_eq!(
ArrkeyError::Annihilation.to_string(),
"key pair annihilation failed"
);
}