Create SSLCertVerificationError with proper attributes Matches CPython's _ssl.c fill_and_set_sslerror() behavior. This function creates a Python SSLCertVerificationError exception with verify_code and verify_message attributes set appropriately for the given rustls certificate error. # Note If attribute setting fails (extremely rare), returns the exception without attributes
(
vm: &VirtualMachine,
cert_err: &rustls::CertificateError,
)
| 218 | /// # Note |
| 219 | /// If attribute setting fails (extremely rare), returns the exception without attributes |
| 220 | pub(super) fn create_ssl_cert_verification_error( |
| 221 | vm: &VirtualMachine, |
| 222 | cert_err: &rustls::CertificateError, |
| 223 | ) -> PyResult<PyBaseExceptionRef> { |
| 224 | let (verify_code, verify_message) = rustls_cert_error_to_verify_info(cert_err); |
| 225 | |
| 226 | let msg = |
| 227 | format!("[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: {verify_message}",); |
| 228 | |
| 229 | let exc = vm.new_os_subtype_error( |
| 230 | PySSLCertVerificationError::class(&vm.ctx).to_owned(), |
| 231 | None, |
| 232 | msg, |
| 233 | ); |
| 234 | |
| 235 | // Set verify_code and verify_message attributes |
| 236 | // Ignore errors as they're extremely rare (e.g., out of memory) |
| 237 | exc.as_object().set_attr( |
| 238 | "verify_code", |
| 239 | vm.ctx.new_int(verify_code).as_object().to_owned(), |
| 240 | vm, |
| 241 | )?; |
| 242 | exc.as_object().set_attr( |
| 243 | "verify_message", |
| 244 | vm.ctx.new_str(verify_message).as_object().to_owned(), |
| 245 | vm, |
| 246 | )?; |
| 247 | |
| 248 | exc.as_object() |
| 249 | .set_attr("library", vm.ctx.new_str("SSL").as_object().to_owned(), vm)?; |
| 250 | exc.as_object().set_attr( |
| 251 | "reason", |
| 252 | vm.ctx |
| 253 | .new_str("CERTIFICATE_VERIFY_FAILED") |
| 254 | .as_object() |
| 255 | .to_owned(), |
| 256 | vm, |
| 257 | )?; |
| 258 | |
| 259 | Ok(exc.upcast()) |
| 260 | } |
| 261 | |
| 262 | /// Unified TLS connection type (client or server) |
| 263 | #[derive(Debug)] |
no test coverage detected