From a0b8f38ab54ac451646aa00cd5e91b6c76f22a84 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:19 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/subtle/tests/mod.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'vendor/subtle/tests') diff --git a/vendor/subtle/tests/mod.rs b/vendor/subtle/tests/mod.rs index eaa98a460..f6b3982e0 100644 --- a/vendor/subtle/tests/mod.rs +++ b/vendor/subtle/tests/mod.rs @@ -1,5 +1,4 @@ -extern crate rand; -extern crate subtle; +use std::cmp; use rand::rngs::OsRng; use rand::RngCore; @@ -96,6 +95,19 @@ fn custom_conditional_select_i16() { assert_eq!(i16::conditional_select(&x, &y, 1.into()), 514); } +#[test] +fn ordering_conditional_select() { + assert_eq!( + cmp::Ordering::conditional_select(&cmp::Ordering::Less, &cmp::Ordering::Greater, 0.into()), + cmp::Ordering::Less + ); + + assert_eq!( + cmp::Ordering::conditional_select(&cmp::Ordering::Less, &cmp::Ordering::Greater, 1.into()), + cmp::Ordering::Greater + ); +} + macro_rules! generate_integer_equal_tests { ($($t:ty),*) => ($( let y: $t = 0; // all 0 bits @@ -105,6 +117,8 @@ macro_rules! generate_integer_equal_tests { assert_eq!(x.ct_eq(&y).unwrap_u8(), 0); assert_eq!(x.ct_eq(&z).unwrap_u8(), 1); + assert_eq!(x.ct_ne(&y).unwrap_u8(), 1); + assert_eq!(x.ct_ne(&z).unwrap_u8(), 0); )*) } @@ -147,6 +161,16 @@ fn choice_equal() { assert!(Choice::from(1).ct_eq(&Choice::from(1)).unwrap_u8() == 1); } +#[test] +fn ordering_equal() { + let a = cmp::Ordering::Equal; + let b = cmp::Ordering::Greater; + let c = a; + + assert_eq!(a.ct_eq(&b).unwrap_u8(), 0); + assert_eq!(a.ct_eq(&c).unwrap_u8(), 1); +} + #[test] fn test_ctoption() { let a = CtOption::new(10, Choice::from(1)); @@ -332,6 +356,12 @@ fn greater_than_u128() { generate_greater_than_test!(u128); } +#[test] +fn greater_than_ordering() { + assert_eq!(cmp::Ordering::Less.ct_gt(&cmp::Ordering::Greater).unwrap_u8(), 0); + assert_eq!(cmp::Ordering::Greater.ct_gt(&cmp::Ordering::Less).unwrap_u8(), 1); +} + #[test] /// Test that the two's compliment min and max, i.e. 0000...0001 < 1111...1110, /// gives the correct result. (This fails using the bit-twiddling algorithm that @@ -387,3 +417,9 @@ fn less_than_u64() { fn less_than_u128() { generate_less_than_test!(u128); } + +#[test] +fn less_than_ordering() { + assert_eq!(cmp::Ordering::Greater.ct_lt(&cmp::Ordering::Less).unwrap_u8(), 0); + assert_eq!(cmp::Ordering::Less.ct_lt(&cmp::Ordering::Greater).unwrap_u8(), 1); +} -- cgit v1.2.3