Trait subtle::ConditionallySelectable [] [src]

pub trait ConditionallySelectable {
    fn conditional_select(a: Self, b: Self, choice: Mask) -> Self;
}

Select a if choice == 1 or select b if choice == 0, in constant time.

Inputs

  • a, b, and choice must be types for which bitwise-AND, and bitwise-OR, bitwise-complement, subtraction, multiplicative identity, copying, partial equality, and partial order comparison are defined.
  • choice: If choice is equal to 1 then a is returned. If choice is equal to 0 then b is returned.

Warning

The behaviour of this function is undefined if choice is something other than a multiplicative identity or additive identity (i.e. 1u8 or 0u8).

If you somehow manage to design a type which is not a signed integer, and yet implements all the requisite trait bounds for this generic, it's your problem if something breaks.

Examples

This function is implemented via a macro for signed integer types:

let a: i32 = 5;
let b: i32 = 13;

assert!(i32::conditional_select(a, b, 0) == 13);
assert!(i32::conditional_select(a, b, 1) == 5);

let c: i64 = 2343249123;
let d: i64 = 8723884895;

assert!(i64::conditional_select(c, d, 0) == d);
assert!(i64::conditional_select(c, d, 1) == c);

Required Methods

Select a if choice == 1 or select b if choice == 0, in constant time.

Inputs

  • a, b, and choice must be types for which bitwise-AND, and bitwise-OR, bitwise-complement, subtraction, multiplicative identity, copying, partial equality, and partial order comparison are defined.
  • choice: If choice is equal to 1 then a is returned. If choice is equal to 0 then b is returned.

Implementations on Foreign Types

impl ConditionallySelectable for i8
[src]

[src]

impl ConditionallySelectable for i16
[src]

[src]

impl ConditionallySelectable for i32
[src]

[src]

impl ConditionallySelectable for i64
[src]

[src]

Implementors