use crate::error::VZResult;
use crate::shim_ffi;
use std::ffi::c_void;
pub struct EntropyDeviceConfiguration {
inner: *mut c_void,
}
unsafe impl Send for EntropyDeviceConfiguration {}
impl EntropyDeviceConfiguration {
pub fn new() -> VZResult<Self> {
let obj = unsafe { shim_ffi::abx_entropy_new() };
Ok(Self { inner: obj })
}
#[must_use]
pub(crate) fn into_ptr(self) -> *mut c_void {
let ptr = self.inner;
std::mem::forget(self);
ptr
}
}
impl Default for EntropyDeviceConfiguration {
fn default() -> Self {
Self::new().expect("Failed to create entropy device")
}
}
impl Drop for EntropyDeviceConfiguration {
fn drop(&mut self) {
if !self.inner.is_null() {
unsafe { shim_ffi::abx_object_release(self.inner.cast()) };
}
}
}