(path: PyUtf8StrRef, vm: &VirtualMachine)
| 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> { |
nothing calls this directly
no test coverage detected