Skip to content

Commit

Permalink
Take a step towards deprecating and removing ring::test.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Mar 9, 2025
1 parent 52b239c commit 75ae17c
Show file tree
Hide file tree
Showing 24 changed files with 50 additions and 41 deletions.
3 changes: 2 additions & 1 deletion cavp/tests/shavs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use wasm_bindgen_test::wasm_bindgen_test_configure;
wasm_bindgen_test_configure!(run_in_browser);

mod digest_shavs {
use ring::{digest, test};
use ring::digest;
use ring::test;

fn run_known_answer_test(digest_alg: &'static digest::Algorithm, test_file: test::File) {
let section_name = &format!("L = {}", digest_alg.output_len());
Expand Down
3 changes: 2 additions & 1 deletion src/arithmetic/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ fn unwrap_impossible_limb_slice_error(err: LimbSliceError) {
#[cfg(test)]
mod tests {
use super::*;
use crate::{cpu, test};
use crate::cpu;
use crate::test;

// Type-level representation of an arbitrary modulus.
struct M {}
Expand Down
14 changes: 0 additions & 14 deletions src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,6 @@ impl Context {
}

/// Returns the digest of `data` using the given digest algorithm.
///
/// # Examples:
///
/// ```
/// # #[cfg(feature = "alloc")]
/// # {
/// use ring::{digest, test};
/// let expected_hex = "09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b";
/// let expected: Vec<u8> = test::from_hex(expected_hex).unwrap();
/// let actual = digest::digest(&digest::SHA256, b"hello, world");
///
/// assert_eq!(&expected, &actual.as_ref());
/// # }
/// ```
pub fn digest(algorithm: &'static Algorithm, data: &[u8]) -> Digest {
let cpu = cpu::features();
Digest::compute_from(algorithm, data, cpu)
Expand Down
3 changes: 2 additions & 1 deletion src/ec/suite_b/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ fn ecdh(
#[cfg(test)]
mod tests {
use super::super::ops;
use crate::{agreement, ec, limb, test};
use crate::{agreement, ec, limb};
use crate::test;

static SUPPORTED_SUITE_B_ALGS: [(&str, &agreement::Algorithm, &ec::Curve, &ops::CommonOps); 2] = [
(
Expand Down
3 changes: 2 additions & 1 deletion src/ec/suite_b/ecdsa/digest_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ fn digest_scalar_(n: &Modulus<N>, digest: &[u8]) -> Scalar {
#[cfg(test)]
mod tests {
use super::digest_bytes_scalar;
use crate::{cpu, digest, ec::suite_b::ops::*, limb, test};
use crate::{cpu, digest, ec::suite_b::ops::*, limb};
use crate::test;

#[test]
fn test() {
Expand Down
3 changes: 2 additions & 1 deletion src/ec/suite_b/ecdsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ static EC_PUBLIC_KEY_P384_PKCS8_V1_TEMPLATE: pkcs8::Template = pkcs8::Template {

#[cfg(test)]
mod tests {
use crate::{rand, signature, test};
use crate::{rand, signature};
use crate::test;

#[test]
fn signature_ecdsa_sign_fixed_test() {
Expand Down
3 changes: 2 additions & 1 deletion src/ec/suite_b/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ pub(super) fn parse_uncompressed_point(
#[cfg(test)]
mod tests {
use super::*;
use crate::{cpu, test};
use crate::cpu;
use crate::test;

#[test]
fn parse_uncompressed_point_test() {
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ mod debug;
#[macro_use]
mod prefixed;

#[doc(hidden)]
#[macro_use]
pub mod test;
pub mod testutil_internal_unstable;

#[deprecated(note = "internal API that will be removed")]
#[doc(hidden)]
pub use testutil_internal_unstable as test;

#[macro_use]
mod bssl;
Expand Down
2 changes: 2 additions & 0 deletions src/polyfill/notsend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ impl NotSend {
pub const VALUE: Self = Self(PhantomData);
}

#[allow(deprecated)]
const _: () = test::compile_time_assert_clone::<NotSend>();
#[allow(deprecated)]
const _: () = test::compile_time_assert_copy::<NotSend>();
const _: () = assert!(size_of::<NotSend>() == 0);
3 changes: 2 additions & 1 deletion src/rsa/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ fn mgf1(digest_alg: &'static digest::Algorithm, seed: &[u8], out: &mut [u8]) {
#[cfg(test)]
mod test {
use super::*;
use crate::{digest, error, test};
use crate::{digest, error};
use crate::test;
use alloc::vec;

#[test]
Expand Down
7 changes: 4 additions & 3 deletions src/test.rs → src/testutil_internal_unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
//! a = 2b11cb945c8cf152ffa4c9c2b1c965b019b35d0b7626919ef0ae6cb9d232f8af
//! b = 18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c
//! r = 18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c
//! thread 'example_test' panicked at 'Test failed.', src\test.rs:206
//! thread 'example_test' panicked at 'Test failed.', src\testutil:206
//! stack backtrace:
//! 0: 0x7ff654a05c7c - std::rt::lang_start::h61f4934e780b4dfc
//! 1: 0x7ff654a04f32 - std::rt::lang_start::h61f4934e780b4dfc
Expand Down Expand Up @@ -295,7 +295,7 @@ impl TestCase {
#[macro_export]
macro_rules! test_file {
($file_name:expr) => {
$crate::test::File {
$crate::testutil_internal_unstable::File {
file_name: $file_name,
contents: include_str!($file_name),
}
Expand Down Expand Up @@ -538,7 +538,8 @@ pub mod rand {

#[cfg(test)]
mod tests {
use crate::{error, test};
use crate::error;
use crate::test;

#[test]
fn one_ok() {
Expand Down
3 changes: 2 additions & 1 deletion tests/aead_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
wasm_bindgen_test_configure!(run_in_browser);

use core::ops::RangeFrom;
use ring::{aead, error, test, test_file};
use ring::{aead, error};
use ring::{test, test_file};

/// Generate the known answer test functions for the given algorithm and test
/// case input file, where each test is implemented by a test in `$test`.
Expand Down
3 changes: 2 additions & 1 deletion tests/agreement_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ wasm_bindgen_test_configure!(run_in_browser);

extern crate alloc;

use ring::{agreement, error, rand, test, test_file};
use ring::{agreement, error, rand};
use ring::{test, test_file};

#[test]
fn agreement_traits() {
Expand Down
3 changes: 2 additions & 1 deletion tests/digest_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

#![allow(missing_docs)]

use ring::{digest, test, test_file};
use ring::digest;
use ring::{test, test_file};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down
2 changes: 1 addition & 1 deletion tests/ecdsa_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use ring::{
rand,
signature::{self, KeyPair},
test, test_file,
};
use ring::{test, test_file};

// ECDSA *signing* tests are in src/ec/ecdsa/signing.rs.

Expand Down
2 changes: 1 addition & 1 deletion tests/ed25519_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use ring::{
error, rand,
signature::{self, Ed25519KeyPair, KeyPair},
test, test_file,
};
use ring::{test, test_file};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down
4 changes: 3 additions & 1 deletion tests/error_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#[cfg(feature = "std")]
#[test]
fn error_impl_std_error_error_test() {
use ring::{error, test};
use ring::error;
use ring::test;

test::compile_time_assert_std_error_error::<error::Unspecified>();
test::compile_time_assert_std_error_error::<error::KeyRejected>();
}
3 changes: 2 additions & 1 deletion tests/hkdf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

#![allow(missing_docs)]

use ring::{digest, error, hkdf, test, test_file};
use ring::{digest, error, hkdf};
use ring::{test, test_file};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down
3 changes: 2 additions & 1 deletion tests/hmac_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

#![allow(missing_docs)]

use ring::{digest, hmac, test, test_file};
use ring::{digest, hmac};
use ring::{test, test_file};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down
3 changes: 2 additions & 1 deletion tests/pbkdf2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#![allow(missing_docs)]

use core::num::NonZeroU32;
use ring::{digest, error, pbkdf2, test, test_file};
use ring::{digest, error, pbkdf2};
use ring::{test, test_file};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down
3 changes: 2 additions & 1 deletion tests/quic_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

#![allow(missing_docs)]

use ring::{aead::quic, test, test_file};
use ring::aead::quic;
use ring::{test_file, test};

#[test]
fn quic_aes_128() {
Expand Down
6 changes: 2 additions & 4 deletions tests/rand_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

#![allow(missing_docs)]

use ring::{
rand::{self, SecureRandom as _},
test,
};
use ring::rand::{self, SecureRandom as _};
use ring::test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down
2 changes: 1 addition & 1 deletion tests/rsa_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use ring::{
io::der,
rand, rsa,
signature::{self, KeyPair},
test, test_file,
};
use ring::{test_file, test};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down
3 changes: 2 additions & 1 deletion tests/signature_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(missing_docs)]

use ring::{signature, test};
use ring::signature;
use ring::test;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
Expand Down

0 comments on commit 75ae17c

Please sign in to comment.