Function constant_time_eq::constant_time_eq
source · pub fn constant_time_eq(a: &[u8], b: &[u8]) -> bool
Expand description
Compares two equal-sized byte strings in constant time.
§Examples
use constant_time_eq::constant_time_eq;
assert!(constant_time_eq(b"foo", b"foo"));
assert!(!constant_time_eq(b"foo", b"bar"));
assert!(!constant_time_eq(b"bar", b"baz"));
// Not equal-sized, so won't take constant time.
assert!(!constant_time_eq(b"foo", b""));
assert!(!constant_time_eq(b"foo", b"quux"));