From f2250d00e18e800e98a4b7ac808c0385e1ee4f91 Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 10 Feb 2024 01:40:02 -0500 Subject: [PATCH] keyfork-entropy: add doctests --- crates/util/keyfork-entropy/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/util/keyfork-entropy/src/lib.rs b/crates/util/keyfork-entropy/src/lib.rs index 9ac68a1..d7512b5 100644 --- a/crates/util/keyfork-entropy/src/lib.rs +++ b/crates/util/keyfork-entropy/src/lib.rs @@ -48,6 +48,12 @@ fn ensure_offline() { } /// Ensure the system is safe. +/// +/// # Examples +/// ```rust +/// # std::env::set_var("SHOOT_SELF_IN_FOOT", "1"); +/// keyfork_entropy::ensure_safe(); +/// ``` pub fn ensure_safe() { if !std::env::vars() .any(|(name, _)| name == "SHOOT_SELF_IN_FOOT" || name == "INSECURE_HARDWARE_ALLOWED") @@ -61,6 +67,16 @@ pub fn ensure_safe() { /// /// # Errors /// An error may be returned if an error occurred while reading from the random source. +/// +/// # Examples +/// ```rust,no_run +/// # fn main() -> Result<(), Box> { +/// # std::env::set_var("SHOOT_SELF_IN_FOOT", "1"); +/// let entropy = keyfork_entropy::generate_entropy_of_size(64)?; +/// assert_eq!(entropy.len(), 64); +/// # Ok(()) +/// # } +/// ``` pub fn generate_entropy_of_size(byte_count: usize) -> Result, std::io::Error> { ensure_safe(); let mut vec = vec![0u8; byte_count];