subtle

Trait ConstantTimeLess

source
pub trait ConstantTimeLess: ConstantTimeEq + ConstantTimeGreater {
    // Provided method
    fn ct_lt(&self, other: &Self) -> Choice { ... }
}
Expand description

A type which can be compared in some manner and be determined to be less than another of the same type.

Provided Methods§

source

fn ct_lt(&self, other: &Self) -> Choice

Determine whether self < other.

The bitwise-NOT of the return value of this function should be usable to determine if self >= other.

A default implementation is provided and implemented for the unsigned integer types.

This function should execute in constant time.

§Returns

A Choice with a set bit if self < other, and with no set bits otherwise.

§Example
use subtle::ConstantTimeLess;

let x: u8 = 13;
let y: u8 = 42;

let x_lt_y = x.ct_lt(&y);

assert_eq!(x_lt_y.unwrap_u8(), 1);

let y_lt_x = y.ct_lt(&x);

assert_eq!(y_lt_x.unwrap_u8(), 0);

let x_lt_x = x.ct_lt(&x);

assert_eq!(x_lt_x.unwrap_u8(), 0);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl ConstantTimeLess for Ordering

source§

fn ct_lt(&self, other: &Self) -> Choice

source§

impl ConstantTimeLess for u8

source§

impl ConstantTimeLess for u16

source§

impl ConstantTimeLess for u32

source§

impl ConstantTimeLess for u64

Implementors§