use std::time::Duration;
use libc::c_double;
use libc::c_int;
use libc::size_t;
use libc::time_t;
use libc::uint8_t;
extern "C" {
fn crypto_seed_rng() -> c_int;
fn crypto_rand(out: *mut uint8_t, out_len: size_t);
fn crypto_strongest_rand(out: *mut uint8_t, out_len: size_t);
fn crypto_rand_time_range(min: time_t, max: time_t) -> time_t;
fn crypto_rand_double() -> c_double;
}
pub fn c_tor_crypto_seed_rng() -> bool {
let ret: c_int;
unsafe {
ret = crypto_seed_rng();
}
match ret {
0 => return true,
_ => return false,
}
}
pub fn c_tor_crypto_rand(dest: &mut [u8]) {
unsafe {
crypto_rand(dest.as_mut_ptr(), dest.len() as size_t);
}
}
pub fn c_tor_crypto_strongest_rand(dest: &mut [u8]) {
unsafe {
crypto_strongest_rand(dest.as_mut_ptr(), dest.len() as size_t);
}
}
pub fn c_tor_crypto_rand_time_range(min: &Duration, max: &Duration) -> Duration {
let ret: time_t;
unsafe {
ret = crypto_rand_time_range(min.as_secs() as time_t, max.as_secs() as time_t);
}
Duration::from_secs(ret as u64)
}
pub fn c_tor_crypto_rand_double() -> f64 {
unsafe { crypto_rand_double() }
}