#![deny(
anonymous_parameters,
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces
)]
#![warn(bare_trait_objects, unreachable_pub, unused_qualifications)]
#[cfg(feature = "cli")]
pub mod cli;
#[cfg(feature = "configuration")]
pub mod configuration;
#[cfg(feature = "crypto")]
pub mod crypto;
pub mod error;
#[cfg(feature = "fs")]
pub mod fs;
#[cfg(feature = "http")]
pub mod http;
#[cfg(feature = "io")]
pub mod io;
#[cfg(feature = "logging")]
pub mod logging;
#[cfg(feature = "net")]
pub mod net;
#[cfg(feature = "testing")]
pub mod testing;
#[cfg(all(
feature = "cli",
feature = "configuration",
feature = "crypto",
feature = "fs",
feature = "http",
feature = "logging",
feature = "net",
feature = "testing"
))]
#[cfg(test)]
mod tests;
use lazy_static::lazy_static;
lazy_static! {
static ref INIT_STATUS: ::std::sync::Mutex<bool> = ::std::sync::Mutex::new(false);
}
#[cfg(feature = "halite-sys")]
fn init_nacl() -> self::error::Result<()> {
if unsafe { halite_sys::sodium_init() } >= 0 {
Ok(())
} else {
Err(error::Error::Internal(format!(
"initializing cryptographic dependencies failed"
)))
}
}
#[cfg(not(feature = "halite-sys"))]
fn init_nacl() -> self::error::Result<()> {
Ok(())
}
pub fn init() -> self::error::Result<()> {
let mut lock = INIT_STATUS.lock().unwrap();
if *lock {
return Ok(());
}
init_nacl()?;
*lock = true;
Ok(())
}
pub fn init_done() -> bool {
*INIT_STATUS.lock().unwrap()
}