| 1 |
//! Tests for `ctutils` integration. |
| 2 |
|
| 3 |
#![cfg(feature = "ctutils")] |
| 4 |
|
| 5 |
use ctutils::{Choice, CtAssign, CtEq, CtSelect}; |
| 6 |
use hybrid_array::{Array, typenum::U3}; |
| 7 |
|
| 8 |
#[test] |
| 9 |
fn ct_assign() { |
| 10 |
let a: Array<u8, U3> = Array([0, 0, 0]); |
| 11 |
let b: Array<u8, U3> = Array([1, 2, 3]); |
| 12 |
let mut c = a; |
| 13 |
|
| 14 |
c.ct_assign(&b, Choice::FALSE); |
| 15 |
assert_eq!(a, c); |
| 16 |
|
| 17 |
c.ct_assign(&b, Choice::TRUE); |
| 18 |
assert_eq!(b, c); |
| 19 |
} |
| 20 |
|
| 21 |
#[test] |
| 22 |
fn ct_eq() { |
| 23 |
let a: Array<u8, U3> = Array([0, 0, 0]); |
| 24 |
let b: Array<u8, U3> = Array([1, 2, 3]); |
| 25 |
|
| 26 |
assert!(a.ct_eq(&a).to_bool()); |
| 27 |
assert!(!a.ct_ne(&a).to_bool()); |
| 28 |
assert!(!a.ct_eq(&b).to_bool()); |
| 29 |
assert!(a.ct_ne(&b).to_bool()); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn ct_select() { |
| 34 |
let a: Array<u8, U3> = Array([0, 0, 0]); |
| 35 |
let b: Array<u8, U3> = Array([1, 2, 3]); |
| 36 |
|
| 37 |
let c = a.ct_select(&b, Choice::FALSE); |
| 38 |
assert_eq!(a, c); |
| 39 |
|
| 40 |
let d = a.ct_select(&b, Choice::TRUE); |
| 41 |
assert_eq!(b, d); |
| 42 |
} |