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

Method load_certs_from_bytes_helper

crates/stdlib/src/ssl.rs:2088–2128  ·  view source on GitHub ↗

Helper: Load certificates from bytes into existing store

(
            &self,
            root_store: &mut RootCertStore,
            ca_certs_der: &mut Vec<Vec<u8>>,
            data: &[u8],
            pem_only: bool,
            vm: &VirtualMachine,
    

Source from the content-addressed store, hash-verified

2086
2087 /// Helper: Load certificates from bytes into existing store
2088 fn load_certs_from_bytes_helper(
2089 &self,
2090 root_store: &mut RootCertStore,
2091 ca_certs_der: &mut Vec<Vec<u8>>,
2092 data: &[u8],
2093 pem_only: bool,
2094 vm: &VirtualMachine,
2095 ) -> PyResult<cert::CertStats> {
2096 let mut loader = cert::CertLoader::new(root_store, ca_certs_der);
2097 // treat_all_as_ca=true: CPython counts all certificates loaded via cadata as CA certs
2098 // regardless of their Basic Constraints extension
2099 // pem_only=true for string input
2100 loader
2101 .load_from_bytes_ex(data, true, pem_only)
2102 .map_err(|e| {
2103 // Preserve specific error messages from cert.rs
2104 let err_msg = e.to_string();
2105 if err_msg.contains("no start line") {
2106 vm.new_os_subtype_error(
2107 PySSLError::class(&vm.ctx).to_owned(),
2108 None,
2109 "no start line: cadata does not contain a certificate",
2110 )
2111 .upcast()
2112 } else if err_msg.contains("not enough data") {
2113 vm.new_os_subtype_error(
2114 PySSLError::class(&vm.ctx).to_owned(),
2115 None,
2116 "not enough data: cadata does not contain a certificate",
2117 )
2118 .upcast()
2119 } else {
2120 vm.new_os_subtype_error(
2121 PySSLError::class(&vm.ctx).to_owned(),
2122 None,
2123 err_msg,
2124 )
2125 .upcast()
2126 }
2127 })
2128 }
2129
2130 /// Helper: Try to parse data as CRL (PEM or DER format)
2131 fn try_parse_crl(

Callers 1

load_verify_locationsMethod · 0.80

Calls 7

newFunction · 0.85
load_from_bytes_exMethod · 0.80
to_stringMethod · 0.80
upcastMethod · 0.80
new_os_subtype_errorMethod · 0.80
containsMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected