Trait subtle::ConditionallyAssignable
[−]
[src]
pub trait ConditionallyAssignable { fn conditional_assign(&mut self, other: &Self, choice: Mask); }
Trait for items which can be conditionally assigned in constant time.
Required Methods
fn conditional_assign(&mut self, other: &Self, choice: Mask)
Conditionally assign other
to self
in constant time.
If choice == 1
, assign other
to self
. Otherwise, leave self
unchanged.
Examples
Several implementations of constant-time conditional assignment are
provided within subtle
.
Integer Types
This crate includes implementations of ConditionallyAssignable
for the
following integer types:
u8
,u16
,u32
,u64
,i8
,i16
,i32
, andi64
.
let mut x: u8 = 13; let y: u8 = 42; x.conditional_assign(&y, 0); assert_eq!(x, 13); x.conditional_assign(&y, 1); assert_eq!(x, 42);
If you need conditional assignment for u128
ori128
on Rust nightly,
these definitions are provided if you compile subtle
with the
nightly
feature:
[dependencies.subtle] features = ["nightly"]
Integer Arrays
Additionally, subtle
provides implementations of conditional
assignment for fixed-size arrays (between [1, 32] elements in length,
inclusive) of integers (for the integer types listed above):
let mut x: [u32; 17] = [13; 17]; let y: [u32; 17] = [42; 17]; x.conditional_assign(&y, 0); assert_eq!(x, [13; 17]); x.conditional_assign(&y, 1); assert_eq!(x, [42; 17]);
If you need conditional assignment for u128
ori128
on Rust nightly,
these definitions are provided if you compile subtle
with the
nightly
feature (as above).