You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I didn't see an obvious way to generate a collection of random bytes so I wrote a quick method to do so in rng.rs:
/// Generates a random collection of bytes. Advances the internal state of the RNG.pubfnrandom_bytes<constN:usize>(&mutself) -> Result<[u8;N]>{let num_bytes:u32 = N.try_into().expect("Failed while trying to convert usize to u32");letmut buf = [0u8;N];matchunsafe{
wolfssl_sys::wc_RNG_GenerateBlock(&mutself.0as*mut_, buf.as_mut_ptr(), num_bytes)}{0 => Ok(buf),
e => Err(Error::fatal(e)),}}
and used it like this which worked fine:
use wolfssl::Random;fnmain(){letmut rand = Random::new().unwrap();let bytes = rand.random_bytes::<32>().unwrap();println!("{bytes:?}");}
Would the maintainers consider adding a method like this to rng?
The text was updated successfully, but these errors were encountered:
I didn't see an obvious way to generate a collection of random bytes so I wrote a quick method to do so in
rng.rs
:and used it like this which worked fine:
Would the maintainers consider adding a method like this to
rng
?The text was updated successfully, but these errors were encountered: