From 473cee9e6ed8698ae78d759a0e69a37df813cb4d Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Tue, 3 Oct 2023 14:24:48 -0400 Subject: [PATCH] add set_mut_ptr helper to ArcCastPtr trait --- src/cipher.rs | 9 ++------- src/lib.rs | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cipher.rs b/src/cipher.rs index 1fc9e0b0..cfe72c75 100644 --- a/src/cipher.rs +++ b/src/cipher.rs @@ -532,9 +532,7 @@ impl rustls_root_cert_store_builder { Some(b) => b, }; - unsafe { - *root_cert_store_out = ArcCastPtr::to_const_ptr(builder.roots.clone()); - } + ArcCastPtr::set_mut_ptr(root_cert_store_out, builder.roots.clone()); rustls_result::Ok } @@ -743,10 +741,7 @@ impl rustls_web_pki_client_cert_verifier_builder { Err(e) => return error::map_verifier_builder_error(e), }; - // TODO(XXX): Is there a safer way to handle this ala BoxCastPtr::set_mut_ptr? - unsafe { - *verifier_out = ArcCastPtr::to_const_ptr(verifier) - } + ArcCastPtr::set_mut_ptr(verifier_out, verifier); rustls_result::Ok } diff --git a/src/lib.rs b/src/lib.rs index b64f446a..2c31dd10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -399,6 +399,12 @@ pub(crate) trait ArcCastPtr: CastConstPtr + Sized { fn to_const_ptr(src: Self::RustType) -> *const Self { Arc::into_raw(Arc::new(src)) as *const _ } + + fn set_mut_ptr(dst: *mut *const Self, src: Self::RustType) { + unsafe { + *dst = Self::to_const_ptr(src); + } + } } #[doc(hidden)]