sodium_sys/crypto/utils/init.rs
1//! This module contains the *init()* function.
2use libc::c_int;
3
4extern "C" {
5 fn sodium_init() -> c_int;
6}
7
8/// *init()* initializes the library and should be called before any other
9/// function provided by sodium_sys. The function can be called more than once,
10/// but it should not be executed by multiple threads simultaneously. Add
11/// appropriate locks around the function call if this scenario can happen in
12/// your application.
13///
14/// After this function returns, all of the other functions provided by
15/// sodium_sys will be thread-safe.
16///
17/// *sodium_init()* doesn't perform any memory allocations. However, on Unix
18/// systems, it opens */dev/urandom* and keeps the descriptor open so that the
19/// device remains accessible after a *chroot()* call. Multiple calls to
20/// *sodium_init()* do not cause additional descriptors to be opened.
21///
22/// *init()* safely wraps *sodium_init()*.
23///
24/// # Examples
25///
26/// ```
27/// use sodium_sys::crypto::utils::init;
28///
29/// assert!(init::init() == 0);
30/// ```
31pub fn init() -> i32 {
32 unsafe {
33 sodium_init()
34 }
35}