boolean_function/
boolean_function_error.rs

1//! Possible errors and panic messages for the boolean function library.
2
3use thiserror::Error;
4
5/// Possible errors for the boolean function library.
6#[derive(Error, Debug, PartialEq, Clone)]
7pub enum BooleanFunctionError {
8    /// Error parsing hex string: the string length must be a power of 2 to represent a truth table.
9    #[error("Hex truth table length must be a power of 2")]
10    WrongStringHexTruthTableLength,
11    /// Error parsing hex string: probably some characters are not valid hex characters.
12    #[error("Error parsing string hex number")]
13    StringHexParseError,
14    /// The Boolean function variable count is too big: it must be $\leq 6$ for [crate::SmallBooleanFunction] and $\leq 31$ for [crate::BooleanFunction] / [crate::BigBooleanFunction].
15    /// The last limit is due to the maximum number of variables that can be represented in a 32-bit integer.
16    #[error("Too big variable count, must be <= {0}")]
17    TooBigVariableCount(usize),
18    /// An unexpected error occurred. This should not happen as the case is supposed to be handled. Please report this issue to the crate maintainer.
19    #[error("Unexpected error, this shouldn't happen. Please report this issue to the crate maintainer.")]
20    UnexpectedError,
21    /// The derivative direction is too big: it must be $< 2^n$, where n is the number of variables.
22    #[error("Too big derivative direction, must be <= {0}")]
23    TooBigDerivativeDirection(u32),
24    /// The Walsh values count is invalid: it must be $2^n$, where $n \geq 2$. n is the number of variables of the Boolean function.
25    #[error("Invalid number of Walsh values {0}, should be 2^n, n >= 2")]
26    InvalidWalshValuesCount(usize),
27    /// The truth table is too big for the number of variables: it must be $< 2^{2^n}$, where n is the number of variables.
28    #[error("Truth table is too big for variables count")]
29    TooBigTruthTableForVarCount,
30    /// Cannot generate close balanced Boolean function iterator, as the given function is already balanced
31    #[error("This Boolean function is already balanced")]
32    AlreadyBalanced,
33    /// Error parsing ANF string, should be in the form "x0*x2*x3 + x2*x3 + x1 + 1"
34    #[error("Error parsing ANF string, should be in the form \"x0*x2*x3 + x2*x3 + x1 + 1\"")]
35    ErrorParsingAnfString,
36    /// The given factor is too big for the variable count. For example, x4 cannot exist if variable count = 4
37    #[error("There are {0} variables in this ANF form, x{1} factor shouldn't appear")]
38    AnfFormNVariableTooBigFactor(usize, usize),
39}
40
41pub(crate) const XOR_DIFFERENT_VAR_COUNT_PANIC_MSG: &'static str =
42    "XOR operation requires the same number of variables in both functions";
43
44pub(crate) const AND_DIFFERENT_VAR_COUNT_PANIC_MSG: &'static str =
45    "AND operation requires the same number of variables in both functions";
46
47#[cfg(not(feature = "unsafe_disable_safety_checks"))]
48pub(crate) const TRUTH_TABLE_TOO_BIG_VAR_COUNT_PANIC_MSG: &'static str =
49    "Truth table is too big for variables count";
50#[cfg(not(feature = "unsafe_disable_safety_checks"))]
51pub(crate) const POLYNOMIAL_ANF_TOO_BIG_VAR_COUNT_PANIC_MSG: &'static str =
52    "Polynomial ANF is too big for variables count";