Skip to content

Commit d129cf5

Browse files
committed
ConstCtOption<NonZero<Limb>>::expect
1 parent 69dec3f commit d129cf5

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`
@@ -293,6 +293,20 @@ impl<const LIMBS: usize> ConstCtOption<NonZero<Uint<LIMBS>>> {
293293
}
294294
}
295295

296+
impl ConstCtOption<NonZero<Limb>> {
297+
/// Returns the contained value, consuming the `self` value.
298+
///
299+
/// # Panics
300+
///
301+
/// Panics if the value is none with a custom panic message provided by
302+
/// `msg`.
303+
#[inline]
304+
pub const fn expect(self, msg: &str) -> NonZero<Limb> {
305+
assert!(self.is_some.is_true_vartime(), "{}", msg);
306+
self.value
307+
}
308+
}
309+
296310
impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize>
297311
ConstCtOption<BernsteinYangInverter<SAT_LIMBS, UNSAT_LIMBS>>
298312
{

0 commit comments

Comments
 (0)