Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,6 @@ macro_rules! safegcd_nlimbs {
};
}

/// Internal implementation detail of [`const_assert_eq`] and [`const_assert_ne`].
#[doc(hidden)]
#[macro_export]
macro_rules! const_assert_n {
($n:ident, $($arg:tt)*) => {{
// TODO(tarcieri): gensym a name so it's unique per invocation of the macro?
mod __const_assert {
pub(super) struct Assert<const $n: usize>;

impl<const $n: usize> Assert<$n> {
pub(super) const ASSERT: () = assert!($($arg)*);
}
}

__const_assert::Assert::<$n>::ASSERT
}};
}

/// Const-friendly assertion that two values are equal.
///
/// The first/leftmost operand MUST be a `usize` constant.
///
/// ```ignore
/// const N: usize = 0;
/// const _: () = crypto_bigint::const_assert_eq!(N, 0, "zero equals zero");
/// ```
#[allow(unused_macros)] // TODO(tarcieri): not ready for external use
macro_rules! const_assert_eq {
($left:ident, $right:expr $(,)?) => (
$crate::const_assert_n!($left, $left == $right)
);
($left:ident, $right:expr, $($arg:tt)+) => (
$crate::const_assert_n!($left, $left == $right, $($arg)+)
);
}

/// Const-friendly assertion that two values are NOT equal.
///
/// The first/leftmost operand MUST be a `usize` constant.
///
/// ```ignore
/// const N: usize = 0;
/// const _: () = crypto_bigint::const_assert_ne!(N, 1, "zero is NOT equal to one");
/// ```
macro_rules! const_assert_ne {
($left:ident, $right:expr $(,)?) => (
$crate::const_assert_n!($left, $left != $right)
);
($left:ident, $right:expr, $($arg:tt)+) => (
$crate::const_assert_n!($left, $left != $right, $($arg)+)
);
}

#[cfg(test)]
mod tests {
#[cfg(target_pointer_width = "32")]
Expand Down
2 changes: 1 addition & 1 deletion src/modular/monty_form/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<const N: usize, const LIMBS: usize, const RHS_LIMBS: usize>
bases_and_exponents: &[(Self, Uint<RHS_LIMBS>); N],
exponent_bits: u32,
) -> Self {
const_assert_ne!(N, 0, "bases_and_exponents must not be empty");
assert!(N != 0, "bases_and_exponents must not be empty");
let params = bases_and_exponents[0].0.params;

let mut bases_and_exponents_montgomery_form =
Expand Down