Skip to main content

sendcipher_core/crypto/
random.rs

1/* Created on 2025.10.19 */
2/* Copyright (c) 2025-2026 Youcef Lemsafer */
3/* SPDX-License-Identifier: MIT */
4
5use rand::RngCore;
6use crate::error::Error;
7
8pub fn get_rand_bytes(length: usize) -> Result<Vec<u8>, Error> {
9    // /!\ Must be a CSPRNG
10    let mut rng = rand::thread_rng();
11    let mut buf = vec![0u8; length];
12    rng.fill_bytes(&mut buf);
13    Ok(buf)
14}