@@ -686,18 +686,47 @@ impl rustls_server_cert_verifier {
686
686
/// `NULL`.
687
687
///
688
688
/// [`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" ) ]
689
691
#[ no_mangle]
690
692
pub extern "C" fn rustls_platform_server_cert_verifier_with_provider (
691
693
provider : * const rustls_crypto_provider ,
692
694
) -> * mut rustls_server_cert_verifier {
693
695
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( ) ;
694
722
let provider = try_clone_arc!( provider) ;
695
723
let verifier: Arc <dyn ServerCertVerifier > =
696
724
match rustls_platform_verifier:: Verifier :: new( provider) {
697
725
Ok ( v) => Arc :: new( v) ,
698
- Err ( _ ) => return core :: ptr :: null_mut ( ) ,
726
+ Err ( e ) => return error :: map_error ( e ) ,
699
727
} ;
700
- to_boxed_mut_ptr( verifier)
728
+ * verifier_out = to_boxed_mut_ptr( verifier) ;
729
+ rustls_result:: Ok
701
730
}
702
731
}
703
732
0 commit comments