Trait subtle::ConditionallySelectable [−][src]
pub trait ConditionallySelectable: Copy { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self; fn conditional_assign(&mut self, other: &Self, choice: Choice) { ... } fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice) { ... } }
A type which can be conditionally selected in constant time.
This trait also provides generic implementations of conditional assignment and conditional swaps.
Required methods
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
Select a or b according to choice.
Returns
aifchoice == Choice(0);bifchoice == Choice(1).
This function should execute in constant time.
Example
use subtle::ConditionallySelectable; let x: u8 = 13; let y: u8 = 42; let z = u8::conditional_select(&x, &y, 0.into()); assert_eq!(z, x); let z = u8::conditional_select(&x, &y, 1.into()); assert_eq!(z, y);
Provided methods
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
Conditionally assign other to self, according to choice.
This function should execute in constant time.
Example
use subtle::ConditionallySelectable; let mut x: u8 = 13; let mut y: u8 = 42; x.conditional_assign(&y, 0.into()); assert_eq!(x, 13); x.conditional_assign(&y, 1.into()); assert_eq!(x, 42);
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
Conditionally swap self and other if choice == 1; otherwise,
reassign both unto themselves.
This function should execute in constant time.
Example
use subtle::ConditionallySelectable; let mut x: u8 = 13; let mut y: u8 = 42; u8::conditional_swap(&mut x, &mut y, 0.into()); assert_eq!(x, 13); assert_eq!(y, 42); u8::conditional_swap(&mut x, &mut y, 1.into()); assert_eq!(x, 42); assert_eq!(y, 13);
Implementations on Foreign Types
impl ConditionallySelectable for u8[src]
impl ConditionallySelectable for u8[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for i8[src]
impl ConditionallySelectable for i8[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for u16[src]
impl ConditionallySelectable for u16[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for i16[src]
impl ConditionallySelectable for i16[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for u32[src]
impl ConditionallySelectable for u32[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for i32[src]
impl ConditionallySelectable for i32[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for u64[src]
impl ConditionallySelectable for u64[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for i64[src]
impl ConditionallySelectable for i64[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for u128[src]
impl ConditionallySelectable for u128[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
impl ConditionallySelectable for i128[src]
impl ConditionallySelectable for i128[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
fn conditional_assign(&mut self, other: &Self, choice: Choice)[src]
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)[src]
Implementors
impl ConditionallySelectable for Choice[src]
impl ConditionallySelectable for Choice[src]fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self[src]
impl<T: ConditionallySelectable> ConditionallySelectable for CtOption<T>[src]
impl<T: ConditionallySelectable> ConditionallySelectable for CtOption<T>[src]