Function sodiumoxide_extras::init_with_rng [] [src]

pub fn init_with_rng<T: Rng>(rng: &mut T) -> Result<(), i32>

Sets libsodium randombytes to use a seeded PRNG implementation and initialises libsodium.

This function is safe to call multiple times concurrently from different threads. It will either always return Ok or will always return Err.

The error will contain either -1 or 1. If the error is -1, the initialisation of libsodium has failed. If the error is 1, libsodium has been successfully initialised elsewhere (e.g. via sodiumoxide::init()) but this means that our attempt to apply this seeded RNG to libsodium has not been actioned.

Each sodiumoxide function which uses the random generator in a new thread will cause a new thread-local instance of the PRNG to be created. Each such instance will be seeded with the same value, meaning for example that two newly-spawned threads calling box_::gen_keypair() will generate identical keys.