Rename to reset_with_context_data

This commit is contained in:
Kornel 2025-06-04 23:17:12 +01:00 committed by Kornel
parent 56e9fef055
commit 05f798adc4
2 changed files with 20 additions and 3 deletions

View File

@ -131,8 +131,6 @@ impl X509StoreContextRef {
/// ///
/// This can be used to provide data to callbacks registered with the context. Use the /// This can be used to provide data to callbacks registered with the context. Use the
/// `Ssl::new_ex_index` method to create an `Index`. /// `Ssl::new_ex_index` method to create an `Index`.
///
/// The previous value, if any, will be returned.
#[corresponds(X509_STORE_CTX_set_ex_data)] #[corresponds(X509_STORE_CTX_set_ex_data)]
pub fn set_ex_data<T>(&mut self, index: Index<X509StoreContext, T>, data: T) { pub fn set_ex_data<T>(&mut self, index: Index<X509StoreContext, T>, data: T) {
if let Some(old) = self.ex_data_mut(index) { 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, &mut self,
trust: store::X509Store, trust: store::X509Store,
cert: X509, cert: X509,

View File

@ -451,14 +451,26 @@ fn test_verify_cert() {
let mut store_bldr = X509StoreBuilder::new().unwrap(); let mut store_bldr = X509StoreBuilder::new().unwrap();
store_bldr.add_cert(ca).unwrap(); store_bldr.add_cert(ca).unwrap();
let store = store_bldr.build(); let store = store_bldr.build();
let empty_store = X509StoreBuilder::new().unwrap().build();
let mut context = X509StoreContext::new().unwrap(); let mut context = X509StoreContext::new().unwrap();
assert!(context assert!(context
.init(&store, &cert, &chain, |c| c.verify_cert()) .init(&store, &cert, &chain, |c| c.verify_cert())
.unwrap()); .unwrap());
assert!(!context
.init(&empty_store, &cert, &chain, |c| c.verify_cert())
.unwrap());
assert!(context assert!(context
.init(&store, &cert, &chain, |c| c.verify_cert()) .init(&store, &cert, &chain, |c| c.verify_cert())
.unwrap()); .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] #[test]