Skip to content

Commit

Permalink
Test RDRAND and use_file implementations.
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Richey <[email protected]>
  • Loading branch information
josephlr committed Jun 20, 2024
1 parent d543f9c commit f078f64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ mod util;
mod custom;
#[cfg(feature = "std")]
mod error_impls;
// If the rdrand feature is enabled, always bring in the rdrand module, so
// that the RDRAND implementation can be tested.
#[cfg(all(
any(target_env = "sgx", feature = "rdrand"),
any(target_arch = "x86_64", target_arch = "x86"),
))]
mod rdrand;

pub use crate::error::Error;

Expand Down Expand Up @@ -330,10 +337,10 @@ cfg_if! {
} else if #[cfg(windows)] {
#[path = "windows.rs"] mod imp;
} else if #[cfg(all(target_arch = "x86_64", target_env = "sgx"))] {
#[path = "rdrand.rs"] mod imp;
use rdrand as imp;
} else if #[cfg(all(feature = "rdrand",
any(target_arch = "x86_64", target_arch = "x86")))] {
#[path = "rdrand.rs"] mod imp;
use rdrand as imp;
} else if #[cfg(all(feature = "js",
any(target_arch = "wasm32", target_arch = "wasm64"),
target_os = "unknown"))] {
Expand Down
6 changes: 6 additions & 0 deletions src/rdrand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn is_rdrand_good() -> bool {
unsafe { self_test() }
}

#[allow(dead_code)]
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
static RDRAND_GOOD: LazyBool = LazyBool::new();
if !RDRAND_GOOD.unsync_init(is_rdrand_good) {
Expand Down Expand Up @@ -121,3 +122,8 @@ unsafe fn rdrand_exact(dest: &mut [MaybeUninit<u8>]) -> Option<()> {
}
Some(())
}

#[cfg(test)]
mod tests {
crate::tests::define_tests!(super::getrandom_inner);
}
5 changes: 5 additions & 0 deletions src/use_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,8 @@ impl<F: FnMut()> Drop for DropGuard<F> {
self.0()
}
}

#[cfg(test)]
mod tests {
crate::tests::define_tests!(super::getrandom_inner);
}

0 comments on commit f078f64

Please sign in to comment.