Skip to main content

LibCtx

Struct LibCtx 

Source
pub struct LibCtx { /* private fields */ }
Expand description

An OpenSSL library context (OSSL_LIB_CTX*).

Wrap in Arc<LibCtx> before passing to algorithm descriptors; they will clone the Arc to keep the context alive.

Implementations§

Source§

impl LibCtx

Source

pub fn new() -> Result<Self, ErrorStack>

Create a new, empty library context.

No providers are loaded by default. Call load_provider at least once before using algorithms.

§Errors

Returns Err if OpenSSL cannot allocate the context.

Source

pub fn load_provider(&self, name: &CStr) -> Result<Provider, ErrorStack>

Load a provider into this library context.

Common provider names:

  • c"default" — standard algorithms.
  • c"fips" — FIPS 140-3 validated algorithms (requires OpenSSL FIPS module).
  • c"base" — must be loaded alongside "fips" for PEM/DER encoders.

The returned Provider keeps the provider loaded until dropped.

§Errors

Returns Err if the provider cannot be loaded.

Source

pub fn as_ptr(&self) -> *mut OSSL_LIB_CTX

Return the raw OSSL_LIB_CTX* pointer. Valid while self is alive.

Source

pub fn load_config(&self, path: &Path) -> Result<(), ErrorStack>

Load an openssl.cnf-format configuration file into this context.

Providers and algorithm configuration declared in the file are activated within this context only — the global default context is not affected.

§Errors

Returns Err if path contains a null byte, the file cannot be read, or the configuration is syntactically invalid.

Source

pub fn load_pkcs11_provider( &self, module: &Path, ) -> Result<Provider, ErrorStack>

Load and activate the pkcs11 provider, pointing it at module.

Writes a minimal openssl.cnf snippet to a temporary file, calls load_config on it, then loads the pkcs11 provider into this context. The temporary file is deleted before this function returns.

The returned Provider keeps the provider active until dropped.

§Errors

Returns Err if module cannot be represented as a valid path string, if the temporary file cannot be written, or if the provider fails to load.

Source

pub unsafe fn from_raw_unowned(ptr: *mut OSSL_LIB_CTX) -> Self

Wrap a raw OSSL_LIB_CTX* that is owned and managed externally.

The resulting LibCtx will NOT call OSSL_LIB_CTX_free when dropped. Use this only when the raw pointer’s lifetime is guaranteed to exceed the LibCtx (e.g. a context received from a FIPS provider callback).

§Safety

The caller must ensure that ptr is a valid, non-null OSSL_LIB_CTX* that remains valid for as long as the returned LibCtx is alive.

Trait Implementations§

Source§

impl Debug for LibCtx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for LibCtx

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for LibCtx

Source§

impl Sync for LibCtx

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.