use super::{Error, Result};
#[inline(always)]
pub fn parameter(condition: bool, name: &'static str, reason: &'static str) -> Result<()> {
if !condition {
return Err(Error::param(name, reason));
}
Ok(())
}
#[inline(always)]
pub fn length(context: &'static str, actual: usize, expected: usize) -> Result<()> {
if actual != expected {
return Err(Error::Length {
context,
expected,
actual,
});
}
Ok(())
}
#[inline(always)]
pub fn min_length(context: &'static str, actual: usize, min: usize) -> Result<()> {
if actual < min {
return Err(Error::Length {
context,
expected: min,
actual,
});
}
Ok(())
}
#[inline(always)]
pub fn max_length(context: &'static str, actual: usize, max: usize) -> Result<()> {
if actual > max {
return Err(Error::Length {
context,
expected: max,
actual,
});
}
Ok(())
}
#[inline(always)]
pub fn authentication(is_valid: bool, algorithm: &'static str) -> Result<()> {
if !is_valid {
return Err(Error::Authentication { algorithm });
}
Ok(())
}