Struct subtle::Choice [−][src]
pub struct Choice(_);
The Choice
struct represents a choice for use in conditional
assignment.
It is a wrapper around a u8
, which should have the value either
1
(true) or 0
(false).
With the nightly
feature enabled, the conversion from u8
to
Choice
passes the value through an optimization barrier, as a
best-effort attempt to prevent the compiler from inferring that the
Choice
value is a boolean. This strategy is based on Tim
Maclean's work on rust-timing-shield
,
which attempts to provide a more comprehensive approach for
preventing software side-channels in Rust code.
The Choice
struct implements operators for AND, OR, XOR, and
NOT, to allow combining Choice
values.
These operations do not short-circuit.
Methods
impl Choice
[src]
impl Choice
pub fn unwrap_u8(&self) -> u8
[src]
pub fn unwrap_u8(&self) -> u8
Unwrap the Choice
wrapper to reveal the underlying u8
.
Note
This function only exists as an escape hatch for the rare case
where it's not possible to use one of the subtle
-provided
trait impls.
Trait Implementations
impl Copy for Choice
[src]
impl Copy for Choice
impl Clone for Choice
[src]
impl Clone for Choice
fn clone(&self) -> Choice
[src]
fn clone(&self) -> Choice
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for Choice
[src]
impl Debug for Choice
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl From<Choice> for bool
[src]
impl From<Choice> for bool
fn from(source: Choice) -> bool
[src]
fn from(source: Choice) -> bool
Convert the Choice
wrapper into a bool
, depending on whether
the underlying u8
was a 0
or a 1
.
Note
This function exists to avoid having higher-level cryptographic protocol implementations duplicating this pattern.
The intended use case for this conversion is at the end of a
higher-level primitive implementation: for example, in checking a keyed
MAC, where the verification should happen in constant-time (and thus use
a Choice
) but it is safe to return a bool
at the end of the
verification.
impl BitAnd for Choice
[src]
impl BitAnd for Choice
type Output = Choice
The resulting type after applying the &
operator.
fn bitand(self, rhs: Choice) -> Choice
[src]
fn bitand(self, rhs: Choice) -> Choice
Performs the &
operation.
impl BitAndAssign for Choice
[src]
impl BitAndAssign for Choice
fn bitand_assign(&mut self, rhs: Choice)
[src]
fn bitand_assign(&mut self, rhs: Choice)
Performs the &=
operation.
impl BitOr for Choice
[src]
impl BitOr for Choice
type Output = Choice
The resulting type after applying the |
operator.
fn bitor(self, rhs: Choice) -> Choice
[src]
fn bitor(self, rhs: Choice) -> Choice
Performs the |
operation.
impl BitOrAssign for Choice
[src]
impl BitOrAssign for Choice
fn bitor_assign(&mut self, rhs: Choice)
[src]
fn bitor_assign(&mut self, rhs: Choice)
Performs the |=
operation.
impl BitXor for Choice
[src]
impl BitXor for Choice
type Output = Choice
The resulting type after applying the ^
operator.
fn bitxor(self, rhs: Choice) -> Choice
[src]
fn bitxor(self, rhs: Choice) -> Choice
Performs the ^
operation.
impl BitXorAssign for Choice
[src]
impl BitXorAssign for Choice
fn bitxor_assign(&mut self, rhs: Choice)
[src]
fn bitxor_assign(&mut self, rhs: Choice)
Performs the ^=
operation.
impl Not for Choice
[src]
impl Not for Choice
type Output = Choice
The resulting type after applying the !
operator.
fn not(self) -> Choice
[src]
fn not(self) -> Choice
Performs the unary !
operation.
impl From<u8> for Choice
[src]
impl From<u8> for Choice