| 1 |
//! Tests for `subtle` crate integration. |
| 2 |
|
| 3 |
#![cfg(feature = "subtle")] |
| 4 |
|
| 5 |
use hybrid_array::{Array, typenum::U3}; |
| 6 |
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq}; |
| 7 |
|
| 8 |
#[test] |
| 9 |
fn constant_time_eq() { |
| 10 |
let a: Array<u8, U3> = Array([0, 0, 0]); |
| 11 |
let b: Array<u8, U3> = Array([1, 2, 3]); |
| 12 |
|
| 13 |
assert!(bool::from(a.ct_eq(&a))); |
| 14 |
assert!(!bool::from(a.ct_ne(&a))); |
| 15 |
assert!(!bool::from(a.ct_eq(&b))); |
| 16 |
assert!(bool::from(a.ct_ne(&b))); |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn conditional_select() { |
| 21 |
let a: Array<u8, U3> = Array([0, 0, 0]); |
| 22 |
let b: Array<u8, U3> = Array([1, 2, 3]); |
| 23 |
|
| 24 |
let c = Array::conditional_select(&a, &b, Choice::from(0)); |
| 25 |
assert_eq!(a, c); |
| 26 |
|
| 27 |
let d = Array::conditional_select(&a, &b, Choice::from(1)); |
| 28 |
assert_eq!(b, d); |
| 29 |
} |