use crate::common::MIN_BIT_LENGTH;
use core::{fmt, result};
use core2::error;
pub type Result = result::Result<num_bigint::BigUint, Error>;
#[derive(Debug)]
pub enum Error {
OsRngInitialization(rand_core::Error),
BitLength(usize),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::OsRngInitialization(ref err) => {
write!(f, "Error initializing OS random number generator: {}", err)
}
Error::BitLength(length) => write!(
f,
"The given bit length is too small; must be at least {}: {}",
MIN_BIT_LENGTH, length
),
}
}
}
impl error::Error for Error {}
impl From<rand_core::Error> for Error {
fn from(err: rand_core::Error) -> Error {
Error::OsRngInitialization(err)
}
}