From aa16061135611c1ac5a11495112e495ef3f7d6d9 Mon Sep 17 00:00:00 2001 From: Kornel Date: Thu, 28 Nov 2024 18:39:45 +0000 Subject: [PATCH] Keep semver compat --- boring/src/ssl/test/custom_verify.rs | 16 ++-------------- boring/src/x509/store.rs | 11 ++++++++++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/boring/src/ssl/test/custom_verify.rs b/boring/src/ssl/test/custom_verify.rs index 8ae18405..64e8f89b 100644 --- a/boring/src/ssl/test/custom_verify.rs +++ b/boring/src/ssl/test/custom_verify.rs @@ -64,13 +64,7 @@ fn untrusted_with_set_cert() { let cert = ssl.peer_certificate().unwrap(); let cert_chain = ssl.peer_cert_chain().unwrap(); - assert_eq!( - unsafe { - #[allow(deprecated)] - store.objects().len() - }, - 0 - ); + assert_eq!(store.objects_len(), 0); X509StoreContext::new() .unwrap() @@ -100,13 +94,7 @@ fn trusted_with_set_cert() { let cert = ssl.peer_certificate().unwrap(); let cert_chain = ssl.peer_cert_chain().unwrap(); - assert_eq!( - unsafe { - #[allow(deprecated)] - store.objects().len() - }, - 1 - ); + assert_eq!(store.objects_len(), 1); X509StoreContext::new() .unwrap() diff --git a/boring/src/x509/store.rs b/boring/src/x509/store.rs index f11cc269..068c759c 100644 --- a/boring/src/x509/store.rs +++ b/boring/src/x509/store.rs @@ -129,6 +129,8 @@ foreign_type_and_impl_send_sync! { } impl X509StoreRef { + /// **Warning: this method is unsound** + /// /// Get a reference to the cache of certificates in this store. /// /// # Safety @@ -137,7 +139,14 @@ impl X509StoreRef { note = "This method is unsound https://github.com/sfackler/rust-openssl/issues/2096" )] #[corresponds(X509_STORE_get0_objects)] - pub unsafe fn objects(&self) -> &StackRef { + pub fn objects(&self) -> &StackRef { unsafe { StackRef::from_ptr(ffi::X509_STORE_get0_objects(self.as_ptr())) } } + + /// For testing only, where it doesn't have to expose an unsafe pointer + #[cfg(test)] + #[allow(deprecated)] + pub fn objects_len(&self) -> usize { + self.objects().len() + } }