Skip to content

Add capability to load symbols from current executable #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions cryptoki/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,37 @@ impl Pkcs11 {
unsafe {
let pkcs11_lib =
cryptoki_sys::Pkcs11::new(filename.as_ref()).map_err(Error::LibraryLoading)?;
let mut list = mem::MaybeUninit::uninit();
Self::_new(pkcs11_lib)
}
}

/// Instantiate a new context from current executable, the PKCS11 implementation is contained in the current executable
pub fn new_from_self() -> Result<Self> {
unsafe {
#[cfg(not(windows))]
let this_lib = libloading::os::unix::Library::this();
#[cfg(windows)]
let this_lib = libloading::os::windows::Library::this()?;
let pkcs11_lib = cryptoki_sys::Pkcs11::from_library(this_lib)?;
Self::_new(pkcs11_lib)
}
}

Rv::from(pkcs11_lib.C_GetFunctionList(list.as_mut_ptr()))
.into_result(Function::GetFunctionList)?;
unsafe fn _new(pkcs11_lib: cryptoki_sys::Pkcs11) -> Result<Self> {
let mut list = mem::MaybeUninit::uninit();

let list_ptr = *list.as_ptr();
Rv::from(pkcs11_lib.C_GetFunctionList(list.as_mut_ptr()))
.into_result(Function::GetFunctionList)?;

Ok(Pkcs11 {
impl_: Arc::new(Pkcs11Impl {
_pkcs11_lib: pkcs11_lib,
function_list: *list_ptr,
}),
initialized: Arc::new(RwLock::new(false)),
})
}
let list_ptr = *list.as_ptr();

Ok(Pkcs11 {
impl_: Arc::new(Pkcs11Impl {
_pkcs11_lib: pkcs11_lib,
function_list: *list_ptr,
}),
initialized: Arc::new(RwLock::new(false)),
})
}

/// Initialize the PKCS11 library
Expand Down
Loading