diff --git a/cavp/tests/shavs.rs b/cavp/tests/shavs.rs index 5594715799..f5654b195e 100644 --- a/cavp/tests/shavs.rs +++ b/cavp/tests/shavs.rs @@ -21,7 +21,9 @@ 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; + #[allow(deprecated)] + 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()); @@ -51,7 +53,9 @@ mod digest_shavs { #[allow(non_snake_case)] mod $algorithm_name { use super::run_known_answer_test; - use ring::{digest, test_file}; + use ring::digest; + #[allow(deprecated)] + use ring::test_file; #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::wasm_bindgen_test as test; diff --git a/src/aead/aes.rs b/src/aead/aes.rs index 13312cd478..d9832aeb21 100644 --- a/src/aead/aes.rs +++ b/src/aead/aes.rs @@ -207,11 +207,11 @@ fn encrypt_iv_xor_block_using_ctr32(key: &impl EncryptCtr32, iv: Iv, mut block: #[cfg(test)] mod tests { use super::*; - use crate::test; + use crate::testutil as test; #[test] pub fn test_aes() { - test::run(test_file!("aes_tests.txt"), |section, test_case| { + test::run(test_vector_file!("aes_tests.txt"), |section, test_case| { assert_eq!(section, ""); let key = consume_key(test_case, "Key"); let input = test_case.consume_bytes("Input"); diff --git a/src/aead/chacha.rs b/src/aead/chacha.rs index 597b459c7a..8d7230b58c 100644 --- a/src/aead/chacha.rs +++ b/src/aead/chacha.rs @@ -201,7 +201,8 @@ mod tests { extern crate alloc; use super::{super::overlapping::IndexError, *}; - use crate::{error, test}; + use crate::error; + use crate::testutil as test; use alloc::vec; const MAX_ALIGNMENT_AND_OFFSET: (usize, usize) = (15, 259); @@ -252,38 +253,41 @@ mod tests { // Reuse a buffer to avoid slowing down the tests with allocations. let mut buf = vec![0u8; 1300]; - test::run(test_file!("chacha_tests.txt"), move |section, test_case| { - assert_eq!(section, ""); - - let key = test_case.consume_bytes("Key"); - let key: &[u8; KEY_LEN] = key.as_slice().try_into()?; - let key = Key::new(*key); - - let ctr = test_case.consume_usize("Ctr"); - let nonce = test_case.consume_bytes("Nonce"); - let input = test_case.consume_bytes("Input"); - let output = test_case.consume_bytes("Output"); - - // Run the test case over all prefixes of the input because the - // behavior of ChaCha20 implementation changes dependent on the - // length of the input. - for len in 0..=input.len() { - #[allow(clippy::cast_possible_truncation)] - chacha20_test_case_inner( - &key, - &nonce, - ctr as u32, - &input[..len], - &output[..len], - &mut buf, - max_alignment_and_offset, - cpu, - &f, - ); - } + test::run( + test_vector_file!("chacha_tests.txt"), + move |section, test_case| { + assert_eq!(section, ""); + + let key = test_case.consume_bytes("Key"); + let key: &[u8; KEY_LEN] = key.as_slice().try_into()?; + let key = Key::new(*key); + + let ctr = test_case.consume_usize("Ctr"); + let nonce = test_case.consume_bytes("Nonce"); + let input = test_case.consume_bytes("Input"); + let output = test_case.consume_bytes("Output"); + + // Run the test case over all prefixes of the input because the + // behavior of ChaCha20 implementation changes dependent on the + // length of the input. + for len in 0..=input.len() { + #[allow(clippy::cast_possible_truncation)] + chacha20_test_case_inner( + &key, + &nonce, + ctr as u32, + &input[..len], + &output[..len], + &mut buf, + max_alignment_and_offset, + cpu, + &f, + ); + } - Ok(()) - }); + Ok(()) + }, + ); } fn chacha20_test_case_inner( diff --git a/src/aead/poly1305.rs b/src/aead/poly1305.rs index b4ce4155e3..70dcda3126 100644 --- a/src/aead/poly1305.rs +++ b/src/aead/poly1305.rs @@ -92,23 +92,26 @@ pub(super) fn sign(key: Key, input: &[u8], cpu_features: cpu::Features) -> Tag { #[cfg(test)] mod tests { use super::*; - use crate::test; + use crate::testutil as test; // Adapted from BoringSSL's crypto/poly1305/poly1305_test.cc. #[test] pub fn test_poly1305() { let cpu_features = cpu::features(); - test::run(test_file!("poly1305_test.txt"), |section, test_case| { - assert_eq!(section, ""); - let key = test_case.consume_bytes("Key"); - let key: &[u8; KEY_LEN] = key.as_slice().try_into().unwrap(); - let input = test_case.consume_bytes("Input"); - let expected_mac = test_case.consume_bytes("MAC"); - let key = Key::new(*key); - let Tag(actual_mac) = sign(key, &input, cpu_features); - assert_eq!(expected_mac, actual_mac.as_ref()); - - Ok(()) - }) + test::run( + test_vector_file!("poly1305_test.txt"), + |section, test_case| { + assert_eq!(section, ""); + let key = test_case.consume_bytes("Key"); + let key: &[u8; KEY_LEN] = key.as_slice().try_into().unwrap(); + let input = test_case.consume_bytes("Input"); + let expected_mac = test_case.consume_bytes("MAC"); + let key = Key::new(*key); + let Tag(actual_mac) = sign(key, &input, cpu_features); + assert_eq!(expected_mac, actual_mac.as_ref()); + + Ok(()) + }, + ) } } diff --git a/src/arithmetic/bigint.rs b/src/arithmetic/bigint.rs index 8d16890749..7251a64ad8 100644 --- a/src/arithmetic/bigint.rs +++ b/src/arithmetic/bigint.rs @@ -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::testutil as test; // Type-level representation of an arbitrary modulus. struct M {} @@ -844,7 +845,7 @@ mod tests { fn test_elem_exp_consttime() { let cpu_features = cpu::features(); test::run( - test_file!("../../crypto/fipsmodule/bn/test/mod_exp_tests.txt"), + test_vector_file!("../../crypto/fipsmodule/bn/test/mod_exp_tests.txt"), |section, test_case| { assert_eq!(section, ""); @@ -927,7 +928,7 @@ mod tests { fn test_elem_mul() { let cpu_features = cpu::features(); test::run( - test_file!("../../crypto/fipsmodule/bn/test/mod_mul_tests.txt"), + test_vector_file!("../../crypto/fipsmodule/bn/test/mod_mul_tests.txt"), |section, test_case| { assert_eq!(section, ""); @@ -952,7 +953,7 @@ mod tests { fn test_elem_squared() { let cpu_features = cpu::features(); test::run( - test_file!("bigint_elem_squared_tests.txt"), + test_vector_file!("bigint_elem_squared_tests.txt"), |section, test_case| { assert_eq!(section, ""); @@ -975,7 +976,7 @@ mod tests { fn test_elem_reduced() { let cpu_features = cpu::features(); test::run( - test_file!("bigint_elem_reduced_tests.txt"), + test_vector_file!("bigint_elem_reduced_tests.txt"), |section, test_case| { assert_eq!(section, ""); @@ -1002,7 +1003,7 @@ mod tests { fn test_elem_reduced_once() { let cpu_features = cpu::features(); test::run( - test_file!("bigint_elem_reduced_once_tests.txt"), + test_vector_file!("bigint_elem_reduced_once_tests.txt"), |section, test_case| { assert_eq!(section, ""); diff --git a/src/deprecated_test.rs b/src/deprecated_test.rs new file mode 100644 index 0000000000..fc0b206ddf --- /dev/null +++ b/src/deprecated_test.rs @@ -0,0 +1,39 @@ +// Copyright 2015-2016 Brian Smith. +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION +// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +#![doc(hidden)] + +/// References a test input file. +#[macro_export] +macro_rules! test_file { + ($file_name:expr) => { + $crate::test::File { + file_name: $file_name, + contents: include_str!($file_name), + } + }; +} + +pub use crate::testutil::{ + compile_time_assert_clone, compile_time_assert_copy, compile_time_assert_eq, + compile_time_assert_send, compile_time_assert_sync, from_hex, run, File, TestCase, +}; + +#[cfg(feature = "std")] +pub use crate::testutil::compile_time_assert_std_error_error; + +#[doc(hidden)] +pub mod rand { + pub use crate::testutil::rand::{FixedByteRandom, FixedSliceRandom, FixedSliceSequenceRandom}; +} diff --git a/src/digest.rs b/src/digest.rs index 857f673f86..e771237786 100644 --- a/src/digest.rs +++ b/src/digest.rs @@ -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 = 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) diff --git a/src/ec/suite_b/ecdh.rs b/src/ec/suite_b/ecdh.rs index 2ffb188b45..59b4374b8f 100644 --- a/src/ec/suite_b/ecdh.rs +++ b/src/ec/suite_b/ecdh.rs @@ -147,7 +147,8 @@ fn ecdh( #[cfg(test)] mod tests { use super::super::ops; - use crate::{agreement, ec, limb, test}; + use crate::testutil as test; + use crate::{agreement, ec, limb}; static SUPPORTED_SUITE_B_ALGS: [(&str, &agreement::Algorithm, &ec::Curve, &ops::CommonOps); 2] = [ ( diff --git a/src/ec/suite_b/ecdsa/digest_scalar.rs b/src/ec/suite_b/ecdsa/digest_scalar.rs index acc4276795..6479c9490c 100644 --- a/src/ec/suite_b/ecdsa/digest_scalar.rs +++ b/src/ec/suite_b/ecdsa/digest_scalar.rs @@ -68,13 +68,14 @@ fn digest_scalar_(n: &Modulus, digest: &[u8]) -> Scalar { #[cfg(test)] mod tests { use super::digest_bytes_scalar; - use crate::{cpu, digest, ec::suite_b::ops::*, limb, test}; + use crate::testutil as test; + use crate::{cpu, digest, ec::suite_b::ops::*, limb}; #[test] fn test() { let cpu = cpu::features(); test::run( - test_file!("ecdsa_digest_scalar_tests.txt"), + test_vector_file!("ecdsa_digest_scalar_tests.txt"), |section, test_case| { assert_eq!(section, ""); diff --git a/src/ec/suite_b/ecdsa/signing.rs b/src/ec/suite_b/ecdsa/signing.rs index a82f6ee8b0..c2bc733c8a 100644 --- a/src/ec/suite_b/ecdsa/signing.rs +++ b/src/ec/suite_b/ecdsa/signing.rs @@ -526,14 +526,15 @@ static EC_PUBLIC_KEY_P384_PKCS8_V1_TEMPLATE: pkcs8::Template = pkcs8::Template { #[cfg(test)] mod tests { - use crate::{rand, signature, test}; + use crate::testutil as test; + use crate::{rand, signature}; #[test] fn signature_ecdsa_sign_fixed_test() { let rng = rand::SystemRandom::new(); test::run( - test_file!("ecdsa_sign_fixed_tests.txt"), + test_vector_file!("ecdsa_sign_fixed_tests.txt"), |section, test_case| { assert_eq!(section, ""); @@ -575,7 +576,7 @@ mod tests { let rng = rand::SystemRandom::new(); test::run( - test_file!("ecdsa_sign_asn1_tests.txt"), + test_vector_file!("ecdsa_sign_asn1_tests.txt"), |section, test_case| { assert_eq!(section, ""); diff --git a/src/ec/suite_b/ecdsa/verification.rs b/src/ec/suite_b/ecdsa/verification.rs index 85121120f3..e500831aa6 100644 --- a/src/ec/suite_b/ecdsa/verification.rs +++ b/src/ec/suite_b/ecdsa/verification.rs @@ -277,14 +277,14 @@ pub static ECDSA_P384_SHA384_ASN1: EcdsaVerificationAlgorithm = EcdsaVerificatio mod tests { extern crate alloc; use super::*; - use crate::test; + use crate::testutil as test; use alloc::{vec, vec::Vec}; #[test] fn test_digest_based_test_vectors() { let cpu = cpu::features(); test::run( - test_file!("../../../../crypto/fipsmodule/ecdsa/ecdsa_verify_tests.txt"), + test_vector_file!("../../../../crypto/fipsmodule/ecdsa/ecdsa_verify_tests.txt"), |section, test_case| { assert_eq!(section, ""); diff --git a/src/ec/suite_b/ops.rs b/src/ec/suite_b/ops.rs index ff3b425692..7c2ed7f208 100644 --- a/src/ec/suite_b/ops.rs +++ b/src/ec/suite_b/ops.rs @@ -613,7 +613,7 @@ fn unwrap_impossible_len_mismatch_error(LenMismatchError { .. }: LenMismatchE mod tests { extern crate alloc; use super::*; - use crate::test; + use crate::testutil as test; use alloc::{format, vec, vec::Vec}; const ZERO_SCALAR: Scalar = Scalar { @@ -660,7 +660,7 @@ mod tests { fn p256_elem_add_test() { elem_add_test( &p256::PUBLIC_SCALAR_OPS, - test_file!("ops/p256_elem_sum_tests.txt"), + test_vector_file!("ops/p256_elem_sum_tests.txt"), ); } @@ -668,7 +668,7 @@ mod tests { fn p384_elem_add_test() { elem_add_test( &p384::PUBLIC_SCALAR_OPS, - test_file!("ops/p384_elem_sum_tests.txt"), + test_vector_file!("ops/p384_elem_sum_tests.txt"), ); } @@ -705,7 +705,7 @@ mod tests { elem_sub_test( &p384::COMMON_OPS, p384_elem_sub, - test_file!("ops/p384_elem_sum_tests.txt"), + test_vector_file!("ops/p384_elem_sum_tests.txt"), ); } @@ -757,7 +757,7 @@ mod tests { elem_div_by_2_test( &p384::COMMON_OPS, p384_elem_div_by_2, - test_file!("ops/p384_elem_div_by_2_tests.txt"), + test_vector_file!("ops/p384_elem_div_by_2_tests.txt"), ); } @@ -793,7 +793,7 @@ mod tests { elem_neg_test( &p256::COMMON_OPS, ecp_nistz256_neg, - test_file!("ops/p256_elem_neg_tests.txt"), + test_vector_file!("ops/p256_elem_neg_tests.txt"), ); } @@ -805,7 +805,7 @@ mod tests { elem_neg_test( &p384::COMMON_OPS, p384_elem_neg, - test_file!("ops/p384_elem_neg_tests.txt"), + test_vector_file!("ops/p384_elem_neg_tests.txt"), ); } @@ -845,12 +845,18 @@ mod tests { #[test] fn p256_elem_mul_test() { - elem_mul_test(&p256::COMMON_OPS, test_file!("ops/p256_elem_mul_tests.txt")); + elem_mul_test( + &p256::COMMON_OPS, + test_vector_file!("ops/p256_elem_mul_tests.txt"), + ); } #[test] fn p384_elem_mul_test() { - elem_mul_test(&p384::COMMON_OPS, test_file!("ops/p384_elem_mul_tests.txt")); + elem_mul_test( + &p384::COMMON_OPS, + test_vector_file!("ops/p384_elem_mul_tests.txt"), + ); } fn elem_mul_test(ops: &'static CommonOps, test_file: test::File) { @@ -872,7 +878,7 @@ mod tests { fn p256_scalar_mul_test() { scalar_mul_test( &p256::SCALAR_OPS, - test_file!("ops/p256_scalar_mul_tests.txt"), + test_vector_file!("ops/p256_scalar_mul_tests.txt"), ); } @@ -880,7 +886,7 @@ mod tests { fn p384_scalar_mul_test() { scalar_mul_test( &p384::SCALAR_OPS, - test_file!("ops/p384_scalar_mul_tests.txt"), + test_vector_file!("ops/p384_scalar_mul_tests.txt"), ); } @@ -908,7 +914,7 @@ mod tests { scalar_square_test( &p256::SCALAR_OPS, p256_scalar_sqr_rep_mont, - test_file!("ops/p256_scalar_square_tests.txt"), + test_vector_file!("ops/p256_scalar_square_tests.txt"), ); } @@ -966,7 +972,7 @@ mod tests { fn p256_point_sum_test() { point_sum_test( &p256::PRIVATE_KEY_OPS, - test_file!("ops/p256_point_sum_tests.txt"), + test_vector_file!("ops/p256_point_sum_tests.txt"), ); } @@ -974,7 +980,7 @@ mod tests { fn p384_point_sum_test() { point_sum_test( &p384::PRIVATE_KEY_OPS, - test_file!("ops/p384_point_sum_tests.txt"), + test_vector_file!("ops/p384_point_sum_tests.txt"), ); } @@ -1007,7 +1013,7 @@ mod tests { point_sum_mixed_test( &p256::PRIVATE_KEY_OPS, p256_point_add_affine, - test_file!("ops/p256_point_sum_mixed_tests.txt"), + test_vector_file!("ops/p256_point_sum_mixed_tests.txt"), ); } @@ -1051,7 +1057,7 @@ mod tests { point_double_test( &p256::PRIVATE_KEY_OPS, p256_point_double, - test_file!("ops/p256_point_double_tests.txt"), + test_vector_file!("ops/p256_point_double_tests.txt"), ); } @@ -1066,7 +1072,7 @@ mod tests { point_double_test( &p384::PRIVATE_KEY_OPS, p384_point_double, - test_file!("ops/p384_point_double_tests.txt"), + test_vector_file!("ops/p384_point_double_tests.txt"), ); } @@ -1105,7 +1111,7 @@ mod tests { point_mul_base_tests( &p256::PRIVATE_KEY_OPS, |s, cpu| p256::PRIVATE_KEY_OPS.point_mul(s, &generator, cpu), - test_file!("ops/p256_point_mul_base_tests.txt"), + test_vector_file!("ops/p256_point_mul_base_tests.txt"), ); } @@ -1120,7 +1126,7 @@ mod tests { point_mul_base_tests( &p384::PRIVATE_KEY_OPS, |s, cpu| p384::PRIVATE_KEY_OPS.point_mul(s, &generator, cpu), - test_file!("ops/p384_point_mul_base_tests.txt"), + test_vector_file!("ops/p384_point_mul_base_tests.txt"), ); } @@ -1129,7 +1135,7 @@ mod tests { point_mul_serialized_test( &p256::PRIVATE_KEY_OPS, &p256::PUBLIC_KEY_OPS, - test_file!("ops/p256_point_mul_serialized_tests.txt"), + test_vector_file!("ops/p256_point_mul_serialized_tests.txt"), ); } @@ -1182,7 +1188,7 @@ mod tests { point_mul_base_tests( &p256::PRIVATE_KEY_OPS, |s, cpu| p256::PRIVATE_KEY_OPS.point_mul_base(s, cpu), - test_file!("ops/p256_point_mul_base_tests.txt"), + test_vector_file!("ops/p256_point_mul_base_tests.txt"), ); } @@ -1191,7 +1197,7 @@ mod tests { point_mul_base_tests( &p384::PRIVATE_KEY_OPS, |s, cpu| p384::PRIVATE_KEY_OPS.point_mul_base(s, cpu), - test_file!("ops/p384_point_mul_base_tests.txt"), + test_vector_file!("ops/p384_point_mul_base_tests.txt"), ); } diff --git a/src/ec/suite_b/ops/p256.rs b/src/ec/suite_b/ops/p256.rs index 0b326f2724..6f3cd02398 100644 --- a/src/ec/suite_b/ops/p256.rs +++ b/src/ec/suite_b/ops/p256.rs @@ -328,7 +328,7 @@ mod tests { point_mul_base_tests( &PRIVATE_KEY_OPS, point_mul_base_vartime, - test_file!("p256_point_mul_base_tests.txt"), + test_vector_file!("p256_point_mul_base_tests.txt"), ); } } diff --git a/src/ec/suite_b/public_key.rs b/src/ec/suite_b/public_key.rs index e48b17854e..328bb371a4 100644 --- a/src/ec/suite_b/public_key.rs +++ b/src/ec/suite_b/public_key.rs @@ -68,13 +68,14 @@ pub(super) fn parse_uncompressed_point( #[cfg(test)] mod tests { use super::*; - use crate::{cpu, test}; + use crate::cpu; + use crate::testutil as test; #[test] fn parse_uncompressed_point_test() { let cpu = cpu::features(); test::run( - test_file!("suite_b_public_key_tests.txt"), + test_vector_file!("suite_b_public_key_tests.txt"), |section, test_case| { assert_eq!(section, ""); diff --git a/src/lib.rs b/src/lib.rs index 04a2e1e7dc..8881809537 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,8 +100,9 @@ mod debug; #[macro_use] mod prefixed; +#[doc(hidden)] #[macro_use] -pub mod test; +mod testutil; #[macro_use] mod bssl; @@ -167,3 +168,10 @@ mod sealed { // ``` pub trait Sealed {} } + +#[deprecated(note = "internal API that will be removed")] +pub mod deprecated_test; + +#[allow(deprecated)] +#[deprecated(note = "internal API that will be removed")] +pub use deprecated_test as test; diff --git a/src/polyfill/notsend.rs b/src/polyfill/notsend.rs index 6f18b2ee16..9c14006f57 100644 --- a/src/polyfill/notsend.rs +++ b/src/polyfill/notsend.rs @@ -12,7 +12,7 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::test; +use crate::testutil; use core::{marker::PhantomData, mem::size_of}; /// A ZST that can be added to any type to make the type `!Send`. @@ -23,6 +23,8 @@ impl NotSend { pub const VALUE: Self = Self(PhantomData); } -const _: () = test::compile_time_assert_clone::(); -const _: () = test::compile_time_assert_copy::(); +#[allow(deprecated)] +const _: () = testutil::compile_time_assert_clone::(); +#[allow(deprecated)] +const _: () = testutil::compile_time_assert_copy::(); const _: () = assert!(size_of::() == 0); diff --git a/src/rsa/keypair.rs b/src/rsa/keypair.rs index 5ef12fecf3..21505d26c1 100644 --- a/src/rsa/keypair.rs +++ b/src/rsa/keypair.rs @@ -641,14 +641,14 @@ impl KeyPair { #[cfg(test)] mod tests { use super::*; - use crate::test; + use crate::testutil as test; use alloc::vec; #[test] fn test_rsakeypair_private_exponentiate() { let cpu = cpu::features(); test::run( - test_file!("keypair_private_exponentiate_tests.txt"), + test_vector_file!("keypair_private_exponentiate_tests.txt"), |section, test_case| { assert_eq!(section, ""); diff --git a/src/rsa/padding.rs b/src/rsa/padding.rs index 628c9d06a7..52253ba439 100644 --- a/src/rsa/padding.rs +++ b/src/rsa/padding.rs @@ -81,13 +81,14 @@ 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::testutil as test; + use crate::{digest, error}; use alloc::vec; #[test] fn test_pss_padding_verify() { test::run( - test_file!("rsa_pss_padding_tests.txt"), + test_vector_file!("rsa_pss_padding_tests.txt"), |section, test_case| { assert_eq!(section, ""); @@ -126,7 +127,7 @@ mod test { #[test] fn test_pss_padding_encode() { test::run( - test_file!("rsa_pss_padding_tests.txt"), + test_vector_file!("rsa_pss_padding_tests.txt"), |section, test_case| { assert_eq!(section, ""); diff --git a/src/test.rs b/src/testutil.rs similarity index 96% rename from src/test.rs rename to src/testutil.rs index 62edd30e41..31cfb98f9a 100644 --- a/src/test.rs +++ b/src/testutil.rs @@ -53,7 +53,7 @@ //! ```ignore //! use ring::test; //! -//! test::run(test::test_file!("hmac_tests.txt"), |section, test_case| { +//! test::run(test::test_vector_file!("hmac_tests.txt"), |section, test_case| { //! assert_eq!(section, ""); // This test doesn't use named sections. //! //! let digest_alg = test_case.consume_digest_alg("HMAC"); @@ -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 @@ -292,10 +292,10 @@ impl TestCase { } /// References a test input file. -#[macro_export] -macro_rules! test_file { +#[cfg(test)] +macro_rules! test_vector_file { ($file_name:expr) => { - $crate::test::File { + $crate::testutil::File { file_name: $file_name, contents: include_str!($file_name), } @@ -538,11 +538,12 @@ pub mod rand { #[cfg(test)] mod tests { - use crate::{error, test}; + use crate::error; + use crate::testutil as test; #[test] fn one_ok() { - test::run(test_file!("test_1_tests.txt"), |_, test_case| { + test::run(test_vector_file!("test_1_tests.txt"), |_, test_case| { let _ = test_case.consume_string("Key"); Ok(()) }); @@ -551,7 +552,7 @@ mod tests { #[test] #[should_panic(expected = "Test failed.")] fn one_err() { - test::run(test_file!("test_1_tests.txt"), |_, test_case| { + test::run(test_vector_file!("test_1_tests.txt"), |_, test_case| { let _ = test_case.consume_string("Key"); Err(error::Unspecified) }); @@ -560,7 +561,7 @@ mod tests { #[test] #[should_panic(expected = "Oh noes!")] fn one_panics() { - test::run(test_file!("test_1_tests.txt"), |_, test_case| { + test::run(test_vector_file!("test_1_tests.txt"), |_, test_case| { let _ = test_case.consume_string("Key"); panic!("Oh noes!"); }); @@ -586,7 +587,7 @@ mod tests { fn err_one(test_to_fail: usize) { let mut n = 0; - test::run(test_file!("test_3_tests.txt"), |_, test_case| { + test::run(test_vector_file!("test_3_tests.txt"), |_, test_case| { let _ = test_case.consume_string("Key"); let result = if n != test_to_fail { Ok(()) @@ -618,7 +619,7 @@ mod tests { fn panic_one(test_to_fail: usize) { let mut n = 0; - test::run(test_file!("test_3_tests.txt"), |_, test_case| { + test::run(test_vector_file!("test_3_tests.txt"), |_, test_case| { let _ = test_case.consume_string("Key"); if n == test_to_fail { panic!("Oh Noes!"); @@ -631,6 +632,9 @@ mod tests { #[test] #[should_panic(expected = "Syntax error: Expected Key = Value.")] fn syntax_error() { - test::run(test_file!("test_1_syntax_error_tests.txt"), |_, _| Ok(())); + test::run( + test_vector_file!("test_1_syntax_error_tests.txt"), + |_, _| Ok(()), + ); } } diff --git a/tests/aead_tests.rs b/tests/aead_tests.rs index 1d14508719..261822f5ad 100644 --- a/tests/aead_tests.rs +++ b/tests/aead_tests.rs @@ -21,7 +21,9 @@ 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}; +#[allow(deprecated)] +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`. diff --git a/tests/agreement_tests.rs b/tests/agreement_tests.rs index 465ebb626d..dc3c56243e 100644 --- a/tests/agreement_tests.rs +++ b/tests/agreement_tests.rs @@ -22,7 +22,9 @@ wasm_bindgen_test_configure!(run_in_browser); extern crate alloc; -use ring::{agreement, error, rand, test, test_file}; +use ring::{agreement, error, rand}; +#[allow(deprecated)] +use ring::{test, test_file}; #[test] fn agreement_traits() { diff --git a/tests/digest_tests.rs b/tests/digest_tests.rs index 9a57d61006..0a3a824826 100644 --- a/tests/digest_tests.rs +++ b/tests/digest_tests.rs @@ -14,7 +14,9 @@ #![allow(missing_docs)] -use ring::{digest, test, test_file}; +use ring::digest; +#[allow(deprecated)] +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}; diff --git a/tests/ecdsa_tests.rs b/tests/ecdsa_tests.rs index 2c3fdf9ab8..83e5abf405 100644 --- a/tests/ecdsa_tests.rs +++ b/tests/ecdsa_tests.rs @@ -17,8 +17,9 @@ use ring::{ rand, signature::{self, KeyPair}, - test, test_file, }; +#[allow(deprecated)] +use ring::{test, test_file}; // ECDSA *signing* tests are in src/ec/ecdsa/signing.rs. diff --git a/tests/ed25519_tests.rs b/tests/ed25519_tests.rs index 9375cbb9e6..2316201582 100644 --- a/tests/ed25519_tests.rs +++ b/tests/ed25519_tests.rs @@ -17,8 +17,9 @@ use ring::{ error, rand, signature::{self, Ed25519KeyPair, KeyPair}, - test, test_file, }; +#[allow(deprecated)] +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}; diff --git a/tests/error_tests.rs b/tests/error_tests.rs index ac10c87744..5fe7cea6b0 100644 --- a/tests/error_tests.rs +++ b/tests/error_tests.rs @@ -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::(); test::compile_time_assert_std_error_error::(); } diff --git a/tests/hkdf_tests.rs b/tests/hkdf_tests.rs index 93234bfe58..64f664bc1d 100644 --- a/tests/hkdf_tests.rs +++ b/tests/hkdf_tests.rs @@ -14,7 +14,9 @@ #![allow(missing_docs)] -use ring::{digest, error, hkdf, test, test_file}; +use ring::{digest, error, hkdf}; +#[allow(deprecated)] +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}; diff --git a/tests/hmac_tests.rs b/tests/hmac_tests.rs index 7097ae4cd6..4a56f30f85 100644 --- a/tests/hmac_tests.rs +++ b/tests/hmac_tests.rs @@ -14,7 +14,9 @@ #![allow(missing_docs)] -use ring::{digest, hmac, test, test_file}; +use ring::{digest, hmac}; +#[allow(deprecated)] +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}; diff --git a/tests/pbkdf2_tests.rs b/tests/pbkdf2_tests.rs index 9bb111e400..a78506e60f 100644 --- a/tests/pbkdf2_tests.rs +++ b/tests/pbkdf2_tests.rs @@ -15,7 +15,9 @@ #![allow(missing_docs)] use core::num::NonZeroU32; -use ring::{digest, error, pbkdf2, test, test_file}; +use ring::{digest, error, pbkdf2}; +#[allow(deprecated)] +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}; diff --git a/tests/quic_tests.rs b/tests/quic_tests.rs index 556a16b2bf..dae30330a3 100644 --- a/tests/quic_tests.rs +++ b/tests/quic_tests.rs @@ -14,7 +14,9 @@ #![allow(missing_docs)] -use ring::{aead::quic, test, test_file}; +use ring::aead::quic; +#[allow(deprecated)] +use ring::{test, test_file}; #[test] fn quic_aes_128() { diff --git a/tests/rand_tests.rs b/tests/rand_tests.rs index bf2b472309..91965362d9 100644 --- a/tests/rand_tests.rs +++ b/tests/rand_tests.rs @@ -14,10 +14,9 @@ #![allow(missing_docs)] -use ring::{ - rand::{self, SecureRandom as _}, - test, -}; +use ring::rand::{self, SecureRandom as _}; +#[allow(deprecated)] +use ring::test; #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/rsa_tests.rs b/tests/rsa_tests.rs index 2b8f141245..5971d1b5cc 100644 --- a/tests/rsa_tests.rs +++ b/tests/rsa_tests.rs @@ -20,8 +20,9 @@ use ring::{ io::der, rand, rsa, signature::{self, KeyPair}, - test, test_file, }; +#[allow(deprecated)] +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}; diff --git a/tests/signature_tests.rs b/tests/signature_tests.rs index 16deacd39b..dd340fab65 100644 --- a/tests/signature_tests.rs +++ b/tests/signature_tests.rs @@ -1,6 +1,8 @@ #![allow(missing_docs)] -use ring::{signature, test}; +use ring::signature; +#[allow(deprecated)] +use ring::test; #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};