(&self, filepath: FsPath, vm: &VirtualMachine)
| 1664 | |
| 1665 | #[pymethod] |
| 1666 | fn load_dh_params(&self, filepath: FsPath, vm: &VirtualMachine) -> PyResult<()> { |
| 1667 | let path = filepath.to_path_buf(vm)?; |
| 1668 | |
| 1669 | // Open the file using fopen (cross-platform) |
| 1670 | let fp = |
| 1671 | rustpython_common::fileutils::fopen(path.as_path(), "rb").map_err(|e| { |
| 1672 | match e.kind() { |
| 1673 | std::io::ErrorKind::NotFound => vm |
| 1674 | .new_os_subtype_error( |
| 1675 | vm.ctx.exceptions.file_not_found_error.to_owned(), |
| 1676 | Some(libc::ENOENT), |
| 1677 | e.to_string(), |
| 1678 | ) |
| 1679 | .upcast(), |
| 1680 | _ => vm.new_os_error(e.to_string()), |
| 1681 | } |
| 1682 | })?; |
| 1683 | |
| 1684 | // Read DH parameters |
| 1685 | let dh = unsafe { |
| 1686 | PEM_read_DHparams( |
| 1687 | fp, |
| 1688 | std::ptr::null_mut(), |
| 1689 | std::ptr::null_mut(), |
| 1690 | std::ptr::null_mut(), |
| 1691 | ) |
| 1692 | }; |
| 1693 | unsafe { |
| 1694 | libc::fclose(fp); |
| 1695 | } |
| 1696 | |
| 1697 | if dh.is_null() { |
| 1698 | return Err(convert_openssl_error(vm, ErrorStack::get())); |
| 1699 | } |
| 1700 | |
| 1701 | // Set temporary DH parameters |
| 1702 | let ctx = self.builder(); |
| 1703 | let result = unsafe { sys::SSL_CTX_set_tmp_dh(ctx.as_ptr(), dh) }; |
| 1704 | unsafe { |
| 1705 | sys::DH_free(dh); |
| 1706 | } |
| 1707 | |
| 1708 | if result != 1 { |
| 1709 | return Err(convert_openssl_error(vm, ErrorStack::get())); |
| 1710 | } |
| 1711 | |
| 1712 | Ok(()) |
| 1713 | } |
| 1714 | |
| 1715 | #[pygetset] |
| 1716 | fn sni_callback(&self) -> Option<PyObjectRef> { |
nothing calls this directly
no test coverage detected