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

Function _test_decode_cert

crates/stdlib/src/ssl.rs:4913–4941  ·  view source on GitHub ↗
(path: PyUtf8StrRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

4911 /// file reading and PEM/DER auto-detection. Used by test suite.
4912 #[pyfunction]
4913 fn _test_decode_cert(path: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
4914 // Read certificate file
4915 let path_str = path.as_str();
4916 let cert_data = std::fs::read(path_str).map_err(|e| {
4917 vm.new_os_error(format!(
4918 "Failed to read certificate file {}: {}",
4919 path_str, e
4920 ))
4921 })?;
4922
4923 // Auto-detect PEM vs DER format
4924 let cert_der = if cert_data
4925 .windows(27)
4926 .any(|w| w == b"-----BEGIN CERTIFICATE-----")
4927 {
4928 // Parse PEM format
4929 let mut cursor = std::io::Cursor::new(&cert_data);
4930 rustls_pemfile::certs(&mut cursor)
4931 .find_map(|r| r.ok())
4932 .ok_or_else(|| vm.new_value_error("No valid certificate found in PEM file"))?
4933 .to_vec()
4934 } else {
4935 // Assume DER format
4936 cert_data
4937 };
4938
4939 // Reuse the comprehensive helper function
4940 cert::cert_der_to_dict_helper(vm, &cert_der)
4941 }
4942
4943 #[pyfunction]
4944 fn DER_cert_to_PEM_cert(der_cert: ArgBytesLike, vm: &VirtualMachine) -> PyResult<PyStrRef> {

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
cert_der_to_dict_helperFunction · 0.85
new_os_errorMethod · 0.80
to_vecMethod · 0.80
ok_or_elseMethod · 0.80
okMethod · 0.80
readFunction · 0.50
as_strMethod · 0.45

Tested by

no test coverage detected