dnscrypt 0.1.1

A pure-Rust DNSCrypt v2 client library — sync and async support.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Thin wrapper around `getrandom` for fixed-size random byte arrays.

/// Fill and return a fresh array of cryptographically secure random bytes.
///
/// # Panics
///
/// Panics if the OS random number generator is unavailable. This is treated
/// as an unrecoverable environment fault: silently continuing without a
/// working CSPRNG would mean generating predictable session keys and
/// nonces, which is a far worse outcome than aborting.
#[allow(clippy::expect_used)]
#[allow(clippy::redundant_pub_crate)] // unreachable_pub requires pub(crate) here; this module is crate-private either way
pub(crate) fn random_bytes<const N: usize>() -> [u8; N] {
    let mut buf = [0u8; N];
    getrandom::fill(&mut buf).expect("getrandom failed: no OS CSPRNG available");
    buf
}