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,
| 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( |
no test coverage detected