1use core::fmt;
2
3use crate::Flavor;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Error {
8 BitLengthTooLarge {
10 bit_length: u32,
12 bits_precision: u32,
14 },
15 BitLengthTooSmall {
17 bit_length: u32,
19 flavor: Flavor,
21 },
22}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
26 match self {
27 Error::BitLengthTooLarge {
28 bit_length,
29 bits_precision,
30 } => write!(
31 f,
32 concat![
33 "The requested bit length of the candidate ({}) ",
34 "is larger than the maximum size of the target integer type ({})."
35 ],
36 bit_length, bits_precision
37 ),
38 Error::BitLengthTooSmall { bit_length, flavor } => write!(
39 f,
40 concat![
41 "The requested bit length of the candidate ({}) ",
42 "is too small to fit a prime of the flavor {:?}",
43 ],
44 bit_length, flavor
45 ),
46 }
47 }
48}