From 9df365abe7b6cca8fea2475fe3e88b5c52d3416d Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 1 Sep 2025 21:22:10 +0200 Subject: [PATCH] fix: support compiling on Windows ARM64 `libc::c_char` in Rust differs by target architecture: - On most platforms (x86-64 Windows, Linux, macOS) it is `i8`. - On Windows ARM64 (AArch64) it is `u8`. This change unconditionally casts pointers with `as *const _`: - On Windows ARM64, this converts `*const i8` to `*const u8` (or vice versa), resolving the type mismatch that caused compilation to fail. - On other platforms, the cast is effectively a no-op but ensures the code compiles everywhere. `CStr::from_ptr` only requires a pointer to a null-terminated byte sequence. The underlying representation of `i8` and `u8` is identical, so the cast is sound. Signed-off-by: filipw --- oqs/src/kem.rs | 4 ++-- oqs/src/sig.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/oqs/src/kem.rs b/oqs/src/kem.rs index 43616691e8..903a7da5a9 100644 --- a/oqs/src/kem.rs +++ b/oqs/src/kem.rs @@ -217,7 +217,7 @@ impl Algorithm { /// This is the same as the `to_id`, but as a safe Rust string. pub fn name(&self) -> &'static str { // SAFETY: The id from ffi must be a proper null terminated C string - let id = unsafe { CStr::from_ptr(self.to_id()) }; + let id = unsafe { CStr::from_ptr(self.to_id() as *const _) }; id.to_str().expect("OQS algorithm names must be UTF-8") } } @@ -282,7 +282,7 @@ impl Kem { pub fn version(&self) -> &'static str { let kem = unsafe { self.kem.as_ref() }; // SAFETY: The alg_version from ffi must be a proper null terminated C string - let cstr = unsafe { CStr::from_ptr(kem.alg_version) }; + let cstr = unsafe { CStr::from_ptr(kem.alg_version as *const _) }; cstr.to_str() .expect("Algorithm version strings must be UTF-8") } diff --git a/oqs/src/sig.rs b/oqs/src/sig.rs index d7268de1d0..e308297409 100644 --- a/oqs/src/sig.rs +++ b/oqs/src/sig.rs @@ -259,7 +259,7 @@ impl Algorithm { /// This is the same as the `to_id`, but as a safe Rust string. pub fn name(&self) -> &'static str { // SAFETY: The id from ffi must be a proper null terminated C string - let id = unsafe { CStr::from_ptr(self.to_id()) }; + let id = unsafe { CStr::from_ptr(self.to_id() as *const _) }; id.to_str().expect("OQS algorithm names must be UTF-8") } } @@ -326,7 +326,7 @@ impl Sig { pub fn version(&self) -> &'static str { let sig = unsafe { self.sig.as_ref() }; // SAFETY: The alg_version from ffi must be a proper null terminated C string - let cstr = unsafe { CStr::from_ptr(sig.alg_version) }; + let cstr = unsafe { CStr::from_ptr(sig.alg_version as *const _) }; cstr.to_str() .expect("Algorithm version strings must be UTF-8") }