Skip to content

Commit eda8ac3

Browse files
committed
Add rustls_platform_server_cert_verifier_try_with_provider
This is `rustls_platform_server_cert_verifier_with_provider` but with a more orderly way of reporting errors. Mark `rustls_platform_server_cert_verifier_with_provider` as deprecated.`
1 parent 813c86d commit eda8ac3

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

librustls/src/rustls.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,8 +2806,26 @@ rustls_result rustls_platform_server_cert_verifier(struct rustls_server_cert_ver
28062806
*
28072807
* [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier
28082808
*/
2809+
DEPRECATED_FUNC("prefer to use rustls_platform_server_cert_verifier_try_with_provider")
28092810
struct rustls_server_cert_verifier *rustls_platform_server_cert_verifier_with_provider(const struct rustls_crypto_provider *provider);
28102811

2812+
/**
2813+
* Create a verifier that uses the default behavior for the current platform.
2814+
*
2815+
* This uses [`rustls-platform-verifier`][] and the specified crypto provider.
2816+
*
2817+
* If the initialization of `rustls-platform-verifier` fails, this function returns
2818+
* an error and `NULL` is written to `verifier_out`. Otherwise it fills in `verifier_out`
2819+
* (whose ownership is transferred to the caller) and returns `RUSTLS_SUCCESS`.
2820+
*
2821+
* The verifier can be used in several `rustls_client_config` instances and must be freed by
2822+
* the application using `rustls_server_cert_verifier_free` when no longer needed.
2823+
*
2824+
* [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier
2825+
*/
2826+
rustls_result rustls_platform_server_cert_verifier_try_with_provider(const struct rustls_crypto_provider *provider,
2827+
struct rustls_server_cert_verifier **verifier_out);
2828+
28112829
/**
28122830
* Free a `rustls_server_cert_verifier` previously returned from
28132831
* `rustls_server_cert_verifier_builder_build` or `rustls_platform_server_cert_verifier`.

librustls/src/verifier.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,18 +686,47 @@ impl rustls_server_cert_verifier {
686686
/// `NULL`.
687687
///
688688
/// [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier
689+
// TODO: remove this function in the next breaking release
690+
#[deprecated(note = "prefer to use rustls_platform_server_cert_verifier_try_with_provider")]
689691
#[no_mangle]
690692
pub extern "C" fn rustls_platform_server_cert_verifier_with_provider(
691693
provider: *const rustls_crypto_provider,
692694
) -> *mut rustls_server_cert_verifier {
693695
ffi_panic_boundary! {
696+
let mut out = core::ptr::null_mut();
697+
Self::rustls_platform_server_cert_verifier_try_with_provider(provider, &mut out);
698+
out
699+
}
700+
}
701+
702+
/// Create a verifier that uses the default behavior for the current platform.
703+
///
704+
/// This uses [`rustls-platform-verifier`][] and the specified crypto provider.
705+
///
706+
/// If the initialization of `rustls-platform-verifier` fails, this function returns
707+
/// an error and `NULL` is written to `verifier_out`. Otherwise it fills in `verifier_out`
708+
/// (whose ownership is transferred to the caller) and returns `RUSTLS_SUCCESS`.
709+
///
710+
/// The verifier can be used in several `rustls_client_config` instances and must be freed by
711+
/// the application using `rustls_server_cert_verifier_free` when no longer needed.
712+
///
713+
/// [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier
714+
#[no_mangle]
715+
pub extern "C" fn rustls_platform_server_cert_verifier_try_with_provider(
716+
provider: *const rustls_crypto_provider,
717+
verifier_out: *mut *mut rustls_server_cert_verifier,
718+
) -> rustls_result {
719+
ffi_panic_boundary! {
720+
let verifier_out = try_mut_from_ptr_ptr!(verifier_out);
721+
*verifier_out = core::ptr::null_mut();
694722
let provider = try_clone_arc!(provider);
695723
let verifier: Arc<dyn ServerCertVerifier> =
696724
match rustls_platform_verifier::Verifier::new(provider) {
697725
Ok(v) => Arc::new(v),
698-
Err(_) => return core::ptr::null_mut(),
726+
Err(e) => return error::map_error(e),
699727
};
700-
to_boxed_mut_ptr(verifier)
728+
*verifier_out = to_boxed_mut_ptr(verifier);
729+
rustls_result::Ok
701730
}
702731
}
703732

0 commit comments

Comments
 (0)