diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs b/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs index 576f63e222..c174bf5d5a 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs @@ -260,9 +260,15 @@ impl VerifyingKey { let mut e = [0u8; MAX_E_LEN]; let mut n_len: u32 = n.len() as u32; let mut e_len: u32 = e.len() as u32; + #[cfg(rsa_const_api)] + let key = &rsa.wc_rsakey; + // SAFETY: older wolfSSL declared the first arg as non-const, but the + // function only reads from the key (newer versions declare it const). + #[cfg(not(rsa_const_api))] + let key = core::ptr::addr_of!(rsa.wc_rsakey) as *mut sys::RsaKey; let rc = unsafe { sys::wc_RsaFlattenPublicKey( - &rsa.wc_rsakey, + key, e.as_mut_ptr(), &mut e_len, n.as_mut_ptr(), &mut n_len, ) @@ -328,9 +334,15 @@ impl Keypair for SigningKey { let mut e = [0u8; MAX_E_LEN]; let mut n_len: u32 = n.len() as u32; let mut e_len: u32 = e.len() as u32; + #[cfg(rsa_const_api)] + let key = &self.inner.wc_rsakey; + // SAFETY: older wolfSSL declared the first arg as non-const, but the + // function only reads from the key (newer versions declare it const). + #[cfg(not(rsa_const_api))] + let key = core::ptr::addr_of!(self.inner.wc_rsakey) as *mut sys::RsaKey; let rc = unsafe { sys::wc_RsaFlattenPublicKey( - &self.inner.wc_rsakey, + key, e.as_mut_ptr(), &mut e_len, n.as_mut_ptr(), &mut n_len, )