galata-vault 0.4.0

End-to-end-encrypted secrets and config documents with no accounts: the galata-vault Rust SDK. A token client and the owner API over a pluggable transport, with an optional in-process backend.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use zeroize::Zeroizing;

/// `N` bytes from the operating system's CSPRNG. There is no fallback: a
/// key generated from anything weaker is not a key.
///
/// A failing OS random source is the one runtime failure here that stops
/// the process instead of returning an error: it is not reachable from any
/// input, nothing sound can continue without randomness, and `OsRng` (which
/// `crypto_box` uses for sealing) already panics the same way. Making every
/// key generation fallible for it would push the case onto every caller.
#[allow(clippy::expect_used)]
pub(crate) fn random_bytes<const N: usize>() -> Zeroizing<[u8; N]> {
    let mut bytes = Zeroizing::new([0u8; N]);
    getrandom::fill(bytes.as_mut_slice()).expect("the operating system's random source failed");
    bytes
}