(
&self,
name: Either<PyStrRef, ArgBytesLike>,
vm: &VirtualMachine,
)
| 1093 | |
| 1094 | #[pymethod] |
| 1095 | fn set_ecdh_curve( |
| 1096 | &self, |
| 1097 | name: Either<PyStrRef, ArgBytesLike>, |
| 1098 | vm: &VirtualMachine, |
| 1099 | ) -> PyResult<()> { |
| 1100 | use openssl::ec::{EcGroup, EcKey}; |
| 1101 | |
| 1102 | // Convert name to CString, supporting both str and bytes |
| 1103 | let name_cstr = match name { |
| 1104 | Either::A(s) => { |
| 1105 | if s.as_str().contains('\0') { |
| 1106 | return Err(exceptions::cstring_error(vm)); |
| 1107 | } |
| 1108 | s.to_cstring(vm)? |
| 1109 | } |
| 1110 | Either::B(b) => std::ffi::CString::new(b.borrow_buf().to_vec()) |
| 1111 | .map_err(|_| exceptions::cstring_error(vm))?, |
| 1112 | }; |
| 1113 | |
| 1114 | // Find the NID for the curve name using OBJ_sn2nid |
| 1115 | let nid_raw = unsafe { sys::OBJ_sn2nid(name_cstr.as_ptr()) }; |
| 1116 | if nid_raw == 0 { |
| 1117 | return Err(vm.new_value_error("unknown curve name")); |
| 1118 | } |
| 1119 | let nid = Nid::from_raw(nid_raw); |
| 1120 | |
| 1121 | // Create EC key from the curve |
| 1122 | let group = EcGroup::from_curve_name(nid).map_err(|e| convert_openssl_error(vm, e))?; |
| 1123 | let key = EcKey::from_group(&group).map_err(|e| convert_openssl_error(vm, e))?; |
| 1124 | |
| 1125 | // Set the temporary ECDH key |
| 1126 | self.builder() |
| 1127 | .set_tmp_ecdh(&key) |
| 1128 | .map_err(|e| convert_openssl_error(vm, e)) |
| 1129 | } |
| 1130 | |
| 1131 | #[pygetset] |
| 1132 | fn options(&self) -> libc::c_ulong { |
nothing calls this directly
no test coverage detected