From 6e60d44196a3e7d24776ff227f3772457c41e787 Mon Sep 17 00:00:00 2001 From: leemeo3 <117142323+leemeo3@users.noreply.github.com> Date: Fri, 12 Jun 2026 09:55:30 +0900 Subject: [PATCH] Add assertions to PublicBox randomize test --- secret-memory/src/public.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/secret-memory/src/public.rs b/secret-memory/src/public.rs index 2d814611..8c1873f0 100644 --- a/secret-memory/src/public.rs +++ b/secret-memory/src/public.rs @@ -560,10 +560,24 @@ mod tests { /// Test the randomize functionality of [PublicBox]. #[test] fn test_public_box_randomize() { + const SAMPLE_COUNT: usize = 8; + let mut pb: PublicBox<32> = PublicBox::zero(); - pb.randomize(); - // Can't really assert anything here until we have can predict the randomness - // by derandomizing the RNG for tests. + let mut samples = [[0u8; 32]; SAMPLE_COUNT]; + + for sample in &mut samples { + pb.randomize(); + *sample = *pb; + } + + assert!( + samples.iter().any(|sample| sample != &[0; 32]), + "PublicBox::randomize should overwrite the zero buffer" + ); + assert!( + samples.windows(2).any(|window| window[0] != window[1]), + "PublicBox::randomize should produce varying samples" + ); } /// Test the [Debug] print of [PublicBox]