From 05f798adc485b7a37028f49a5828fa5bf07aadf3 Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 4 Jun 2025 23:17:12 +0100 Subject: [PATCH] Rename to reset_with_context_data --- boring/src/x509/mod.rs | 11 ++++++++--- boring/src/x509/tests/mod.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/boring/src/x509/mod.rs b/boring/src/x509/mod.rs index 0ebb83aa..e9b2937c 100644 --- a/boring/src/x509/mod.rs +++ b/boring/src/x509/mod.rs @@ -131,8 +131,6 @@ impl X509StoreContextRef { /// /// This can be used to provide data to callbacks registered with the context. Use the /// `Ssl::new_ex_index` method to create an `Index`. - /// - /// The previous value, if any, will be returned. #[corresponds(X509_STORE_CTX_set_ex_data)] pub fn set_ex_data(&mut self, index: Index, data: T) { if let Some(old) = self.ex_data_mut(index) { @@ -207,7 +205,14 @@ impl X509StoreContextRef { } } - pub fn init_without_cleanup( + /// Initializes this context with the given certificate, certificates chain and certificate + /// store. + /// + /// * `trust` - The certificate store with the trusted certificates. + /// * `cert` - The certificate that should be verified. + /// * `cert_chain` - The certificates chain. + #[corresponds(X509_STORE_CTX_init)] + pub fn reset_with_context_data( &mut self, trust: store::X509Store, cert: X509, diff --git a/boring/src/x509/tests/mod.rs b/boring/src/x509/tests/mod.rs index b3867ce2..f02c3fe3 100644 --- a/boring/src/x509/tests/mod.rs +++ b/boring/src/x509/tests/mod.rs @@ -451,14 +451,26 @@ fn test_verify_cert() { let mut store_bldr = X509StoreBuilder::new().unwrap(); store_bldr.add_cert(ca).unwrap(); let store = store_bldr.build(); + let empty_store = X509StoreBuilder::new().unwrap().build(); let mut context = X509StoreContext::new().unwrap(); assert!(context .init(&store, &cert, &chain, |c| c.verify_cert()) .unwrap()); + assert!(!context + .init(&empty_store, &cert, &chain, |c| c.verify_cert()) + .unwrap()); assert!(context .init(&store, &cert, &chain, |c| c.verify_cert()) .unwrap()); + + context + .reset_with_context_data(empty_store, cert.clone(), Stack::new().unwrap()) + .unwrap(); + assert!(!context.verify_cert().unwrap()); + + context.reset_with_context_data(store, cert, chain).unwrap(); + assert!(context.verify_cert().unwrap()); } #[test]