keyfork-entropy: add doctests
This commit is contained in:
parent
4e66367376
commit
f2250d00e1
|
@ -48,6 +48,12 @@ fn ensure_offline() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure the system is safe.
|
/// Ensure the system is safe.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```rust
|
||||||
|
/// # std::env::set_var("SHOOT_SELF_IN_FOOT", "1");
|
||||||
|
/// keyfork_entropy::ensure_safe();
|
||||||
|
/// ```
|
||||||
pub fn ensure_safe() {
|
pub fn ensure_safe() {
|
||||||
if !std::env::vars()
|
if !std::env::vars()
|
||||||
.any(|(name, _)| name == "SHOOT_SELF_IN_FOOT" || name == "INSECURE_HARDWARE_ALLOWED")
|
.any(|(name, _)| name == "SHOOT_SELF_IN_FOOT" || name == "INSECURE_HARDWARE_ALLOWED")
|
||||||
|
@ -61,6 +67,16 @@ pub fn ensure_safe() {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// An error may be returned if an error occurred while reading from the random source.
|
/// An error may be returned if an error occurred while reading from the random source.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```rust,no_run
|
||||||
|
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
/// # 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<Vec<u8>, std::io::Error> {
|
pub fn generate_entropy_of_size(byte_count: usize) -> Result<Vec<u8>, std::io::Error> {
|
||||||
ensure_safe();
|
ensure_safe();
|
||||||
let mut vec = vec![0u8; byte_count];
|
let mut vec = vec![0u8; byte_count];
|
||||||
|
|
Loading…
Reference in New Issue