pub struct Choice(/* private fields */);Expand description
A boolean that can be combined and consumed without secret-dependent branching.
Internally a u8 that is always 0 (false) or 1 (true). Combine choices
with the bitwise operators (&, |, ^, !); turn one into a real
bool only at the end of a computation, once the result is public —
that conversion is not constant time.
Implementations§
Trait Implementations§
Source§impl BitAndAssign for Choice
impl BitAndAssign for Choice
Source§fn bitand_assign(&mut self, rhs: Choice)
fn bitand_assign(&mut self, rhs: Choice)
Performs the
&= operation. Read moreSource§impl BitOrAssign for Choice
impl BitOrAssign for Choice
Source§fn bitor_assign(&mut self, rhs: Choice)
fn bitor_assign(&mut self, rhs: Choice)
Performs the
|= operation. Read moreSource§impl BitXorAssign for Choice
impl BitXorAssign for Choice
Source§fn bitxor_assign(&mut self, rhs: Choice)
fn bitxor_assign(&mut self, rhs: Choice)
Performs the
^= operation. Read moreSource§impl ConditionallySelectable for Choice
impl ConditionallySelectable for Choice
Source§fn conditional_select(a: &Choice, b: &Choice, choice: Choice) -> Choice
fn conditional_select(a: &Choice, b: &Choice, choice: Choice) -> Choice
Returns
a if choice is true, otherwise b, without a
secret-dependent branch.Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Sets
self to other if choice is true, otherwise leaves it
unchanged.Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
Swaps
a and b if choice is true, otherwise leaves them unchanged.Source§impl ConstantTimeEq for Choice
impl ConstantTimeEq for Choice
impl Copy for Choice
Source§impl From<u8> for Choice
impl From<u8> for Choice
Source§fn from(value: u8) -> Self
fn from(value: u8) -> Self
Wraps a 0/1 byte as a Choice.
Debug builds assert the input is 0 or 1. Release builds mask
value & 1 so an out-of-domain byte is silently coerced to a valid
Choice rather than corrupting downstream constant-time selects.
(Internal callers should still keep the bit clean — the mask is a
safety net, not a license to pass arbitrary bytes.)
Auto Trait Implementations§
impl Freeze for Choice
impl RefUnwindSafe for Choice
impl Send for Choice
impl Sync for Choice
impl Unpin for Choice
impl UnsafeUnpin for Choice
impl UnwindSafe for Choice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more