Convert to Python exception
(self, vm: &VirtualMachine)
| 548 | |
| 549 | /// Convert to Python exception |
| 550 | pub fn into_py_err(self, vm: &VirtualMachine) -> PyBaseExceptionRef { |
| 551 | match self { |
| 552 | SslError::WantRead => create_ssl_want_read_error(vm).upcast(), |
| 553 | SslError::WantWrite => create_ssl_want_write_error(vm).upcast(), |
| 554 | SslError::Timeout(msg) => timeout_error_msg(vm, msg).upcast(), |
| 555 | SslError::Syscall(msg) => { |
| 556 | // SSLSyscallError with errno=SSL_ERROR_SYSCALL (5) |
| 557 | create_ssl_syscall_error(vm, msg).upcast() |
| 558 | } |
| 559 | SslError::Ssl(msg) => vm |
| 560 | .new_os_subtype_error( |
| 561 | PySSLError::class(&vm.ctx).to_owned(), |
| 562 | None, |
| 563 | format!("SSL error: {msg}"), |
| 564 | ) |
| 565 | .upcast(), |
| 566 | SslError::ZeroReturn => create_ssl_zero_return_error(vm).upcast(), |
| 567 | SslError::Eof => create_ssl_eof_error(vm).upcast(), |
| 568 | SslError::PreauthData => { |
| 569 | // Non-TLS data received before handshake |
| 570 | Self::create_ssl_error_with_reason( |
| 571 | vm, |
| 572 | None, |
| 573 | "before TLS handshake with data", |
| 574 | "before TLS handshake with data", |
| 575 | ) |
| 576 | } |
| 577 | SslError::CertVerification(cert_err) => { |
| 578 | // Use the proper cert verification error creator |
| 579 | create_ssl_cert_verification_error(vm, &cert_err).expect("unlikely to happen") |
| 580 | } |
| 581 | SslError::Io(err) => err.into_pyexception(vm), |
| 582 | SslError::SniCallbackRestart => { |
| 583 | // This should be handled at PySSLSocket level |
| 584 | unreachable!("SniCallbackRestart should not reach Python layer") |
| 585 | } |
| 586 | SslError::Py(exc) => exc, |
| 587 | SslError::AlertReceived { lib, reason } => { |
| 588 | Self::create_ssl_error_from_codes(vm, lib, reason) |
| 589 | } |
| 590 | SslError::NoCipherSuites => { |
| 591 | // OpenSSL error: lib=20 (ERR_LIB_SSL), reason=193 (SSL_R_NO_SHARED_CIPHER) |
| 592 | Self::create_ssl_error_from_codes(vm, ERR_LIB_SSL, SSL_R_NO_SHARED_CIPHER) |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | pub type SslResult<T> = Result<T, SslError>; |
no test coverage detected