MCPcopy Index your code
hub / github.com/RustPython/RustPython / cert_store_stats

Method cert_store_stats

crates/stdlib/src/openssl.rs:1584–1634  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1582
1583 #[pymethod]
1584 fn cert_store_stats(&self, vm: &VirtualMachine) -> PyResult {
1585 let ctx = self.ctx();
1586 let store_ptr = unsafe { sys::SSL_CTX_get_cert_store(ctx.as_ptr()) };
1587
1588 if store_ptr.is_null() {
1589 return Err(vm.new_memory_error("failed to get cert store"));
1590 }
1591
1592 let objs_ptr = unsafe { sys::X509_STORE_get0_objects(store_ptr) };
1593 if objs_ptr.is_null() {
1594 return Err(vm.new_memory_error("failed to query cert store"));
1595 }
1596
1597 let mut x509_count = 0;
1598 let mut crl_count = 0;
1599 let mut ca_count = 0;
1600
1601 unsafe {
1602 let num_objs = sys::OPENSSL_sk_num(objs_ptr as *const _);
1603 for i in 0..num_objs {
1604 let obj_ptr =
1605 sys::OPENSSL_sk_value(objs_ptr as *const _, i) as *const sys::X509_OBJECT;
1606 let obj_type = X509_OBJECT_get_type(obj_ptr);
1607
1608 match obj_type {
1609 X509_LU_X509 => {
1610 x509_count += 1;
1611 let x509_ptr = sys::X509_OBJECT_get0_X509(obj_ptr);
1612 // X509_check_ca returns non-zero for any CA type
1613 if !x509_ptr.is_null() && X509_check_ca(x509_ptr) != 0 {
1614 ca_count += 1;
1615 }
1616 }
1617 X509_LU_CRL => {
1618 crl_count += 1;
1619 }
1620 _ => {
1621 // Ignore unrecognized types
1622 }
1623 }
1624 }
1625 // Note: No need to free objs_ptr as X509_STORE_get0_objects returns
1626 // a pointer to internal data that should not be freed by the caller
1627 }
1628
1629 let dict = vm.ctx.new_dict();
1630 dict.set_item("x509", vm.ctx.new_int(x509_count).into(), vm)?;
1631 dict.set_item("crl", vm.ctx.new_int(crl_count).into(), vm)?;
1632 dict.set_item("x509_ca", vm.ctx.new_int(ca_count).into(), vm)?;
1633 Ok(dict.into())
1634 }
1635
1636 #[pymethod]
1637 fn session_stats(&self, vm: &VirtualMachine) -> PyResult {

Callers

nothing calls this directly

Calls 6

new_dictMethod · 0.80
ErrClass · 0.50
ctxMethod · 0.45
as_ptrMethod · 0.45
set_itemMethod · 0.45
new_intMethod · 0.45

Tested by

no test coverage detected