Skip to content

Commit fc9a322

Browse files
committed
ConstCtOption<NonZero<Limb>>::expect
1 parent 8fee3a0 commit fc9a322

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/const_choice.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use subtle::{Choice, CtOption};
22

3-
use crate::{modular::BernsteinYangInverter, NonZero, Uint, Word};
3+
use crate::{modular::BernsteinYangInverter, Limb, NonZero, Uint, Word};
44

55
/// A boolean value returned by constant-time `const fn`s.
66
// TODO: should be replaced by `subtle::Choice` or `CtOption`
@@ -305,6 +305,20 @@ impl<const LIMBS: usize> ConstCtOption<NonZero<Uint<LIMBS>>> {
305305
}
306306
}
307307

308+
impl ConstCtOption<NonZero<Limb>> {
309+
/// Returns the contained value, consuming the `self` value.
310+
///
311+
/// # Panics
312+
///
313+
/// Panics if the value is none with a custom panic message provided by
314+
/// `msg`.
315+
#[inline]
316+
pub const fn expect(self, msg: &str) -> NonZero<Limb> {
317+
assert!(self.is_some.is_true_vartime(), "{}", msg);
318+
self.value
319+
}
320+
}
321+
308322
impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize>
309323
ConstCtOption<BernsteinYangInverter<SAT_LIMBS, UNSAT_LIMBS>>
310324
{

0 commit comments

Comments
 (0)