Trait subtle::ConstantTimeEq [−][src]
An Eq-like trait that produces a Choice instead of a bool.
Example
use subtle::ConstantTimeEq; let x: u8 = 5; let y: u8 = 13; assert_eq!(x.ct_eq(&y).unwrap_u8(), 0); assert_eq!(x.ct_eq(&x).unwrap_u8(), 1);
Required Methods
fn ct_eq(&self, other: &Self) -> Choice
Determine if two items are equal.
The ct_eq function should execute in constant time.
Returns
Choice(1u8)ifself == other;Choice(0u8)ifself != other.
Implementations on Foreign Types
impl<T: ConstantTimeEq> ConstantTimeEq for [T][src]
impl<T: ConstantTimeEq> ConstantTimeEq for [T]fn ct_eq(&self, _rhs: &[T]) -> Choice[src]
fn ct_eq(&self, _rhs: &[T]) -> ChoiceCheck whether two slices of ConstantTimeEq types are equal.
Note
This function short-circuits if the lengths of the input slices are different. Otherwise, it should execute in time independent of the slice contents.
Since arrays coerce to slices, this function works with fixed-size arrays:
let a: [u8; 8] = [0,1,2,3,4,5,6,7]; let b: [u8; 8] = [0,1,2,3,0,1,2,3]; let a_eq_a = a.ct_eq(&a); let a_eq_b = a.ct_eq(&b); assert_eq!(a_eq_a.unwrap_u8(), 1); assert_eq!(a_eq_b.unwrap_u8(), 0);
impl ConstantTimeEq for u8[src]
impl ConstantTimeEq for u8impl ConstantTimeEq for i8[src]
impl ConstantTimeEq for i8impl ConstantTimeEq for u16[src]
impl ConstantTimeEq for u16impl ConstantTimeEq for i16[src]
impl ConstantTimeEq for i16impl ConstantTimeEq for u32[src]
impl ConstantTimeEq for u32impl ConstantTimeEq for i32[src]
impl ConstantTimeEq for i32impl ConstantTimeEq for u64[src]
impl ConstantTimeEq for u64impl ConstantTimeEq for i64[src]
impl ConstantTimeEq for i64impl ConstantTimeEq for u128[src]
impl ConstantTimeEq for u128impl ConstantTimeEq for i128[src]
impl ConstantTimeEq for i128impl ConstantTimeEq for usize[src]
impl ConstantTimeEq for usizeimpl ConstantTimeEq for isize[src]
impl ConstantTimeEq for isize