2 use crate::error
::ErrorStack
;
3 use crate::lib_ctx
::LibCtxRef
;
4 use foreign_types
::{ForeignType, ForeignTypeRef}
;
5 use openssl_macros
::corresponds
;
9 foreign_type_and_impl_send_sync
! {
10 type CType
= ffi
::OSSL_PROVIDER
;
11 fn drop
= ossl_provider_free
;
14 /// A reference to a [`Provider`].
15 pub struct ProviderRef
;
19 unsafe fn ossl_provider_free(p
: *mut ffi
::OSSL_PROVIDER
) {
20 ffi
::OSSL_PROVIDER_unload(p
);
24 /// Loads a new provider into the specified library context, disabling the fallback providers.
26 /// If `ctx` is `None`, the provider will be loaded in to the default library context.
27 #[corresponds(OSSL_provider_load)]
28 pub fn load(ctx
: Option
<&LibCtxRef
>, name
: &str) -> Result
<Self, ErrorStack
> {
29 let name
= CString
::new(name
).unwrap();
31 let p
= cvt_p(ffi
::OSSL_PROVIDER_load(
32 ctx
.map_or(ptr
::null_mut(), ForeignTypeRef
::as_ptr
),
36 Ok(Provider
::from_ptr(p
))
40 /// Loads a new provider into the specified library context, disabling the fallback providers if `retain_fallbacks`
41 /// is `false` and the load succeeds.
43 /// If `ctx` is `None`, the provider will be loaded into the default library context.
44 #[corresponds(OSSL_provider_try_load)]
46 ctx
: Option
<&LibCtxRef
>,
48 retain_fallbacks
: bool
,
49 ) -> Result
<Self, ErrorStack
> {
50 let name
= CString
::new(name
).unwrap();
52 let p
= cvt_p(ffi
::OSSL_PROVIDER_try_load(
53 ctx
.map_or(ptr
::null_mut(), ForeignTypeRef
::as_ptr
),
55 retain_fallbacks
as _
,
58 Ok(Provider
::from_ptr(p
))