aura-gui 0.2.2

UI nativa acelerada por GPU para escritorio, Android e iOS, en un solo crate: estilo tipo Tailwind, componentes, sombras, animaciones y agentes de IA. Reposo a cero. Licencia AGPL-3.0 o comercial.
//! Bytes aleatorios del sistema operativo, aptos para claves y verificadores PKCE.

/// Llena `buffer` con bytes del generador criptográfico del sistema.
pub fn fill_random(buffer: &mut [u8]) -> Result<(), String> {
    #[cfg(windows)]
    {
        super::sys::fill_random(buffer)
    }
    #[cfg(not(windows))]
    {
        use std::io::Read;
        std::fs::File::open("/dev/urandom")
            .and_then(|mut file| file.read_exact(buffer))
            .map_err(|error| format!("no hay fuente de aleatoriedad: {error}"))
    }
}

/// `N` bytes aleatorios en la pila.
pub fn random_bytes<const N: usize>() -> Result<[u8; N], String> {
    let mut bytes = [0u8; N];
    fill_random(&mut bytes)?;
    Ok(bytes)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn dos_lecturas_difieren_y_no_son_cero() {
        let (a, b) = (random_bytes::<32>().unwrap(), random_bytes::<32>().unwrap());
        assert_ne!(a, b);
        assert_ne!(a, [0; 32]);
    }
}