summaryrefslogtreecommitdiffstats
path: root/vendor/subtle/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/subtle/tests
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/subtle/tests')
-rw-r--r--vendor/subtle/tests/mod.rs40
1 files changed, 38 insertions, 2 deletions
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);
)*)
}
@@ -148,6 +162,16 @@ fn choice_equal() {
}
#[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));
let b = CtOption::new(9, Choice::from(1));
@@ -333,6 +357,12 @@ fn greater_than_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
/// go/crypto/subtle uses.)
@@ -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);
+}