Skip to content

Commit

Permalink
Add new_unchecked API
Browse files Browse the repository at this point in the history
In some scenarios we cannot use `cpuid` (e.g. for now in Coconut SVSM)
or we want to force the use of `rdrand` and `rdseed`, so let's provide a
new unsafe constructor.

Signed-off-by: Stefano Garzarella <[email protected]>
  • Loading branch information
stefano-garzarella committed Dec 5, 2023
1 parent daf7325 commit b4c39a3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ macro_rules! impl_rand {
}
}

/// Create a new instance of the random number generator.
///
/// # Safety
///
/// This constructor is unsafe because it doesn't check that the CPU supports the
/// instruction, but devolves this responsibility to the caller.
pub unsafe fn new_unchecked() -> Self {
$gen(())
}

/// Generate a single random `u16` value.
///
/// The underlying instruction may fail for variety reasons (such as actual hardware
Expand Down

0 comments on commit b4c39a3

Please sign in to comment.