[][src]Function rust_sodium_sys::init_with_rng

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

Sets libsodium's randombytes_implementation to use a Rust Rng implementation and initialises libsodium.

This allows a seeded PRNG to be used for example, which can be helpful in test scenarios when predictable results may be preferred.

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 rust_sodium::init()) but this means that our attempt to apply this seeded RNG to libsodium has not been actioned.

Each rust_sodium 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.