Skip to content

Commit 9df365a

Browse files
committed
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 <[email protected]>
1 parent 4862ffb commit 9df365a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

oqs/src/kem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl Algorithm {
217217
/// This is the same as the `to_id`, but as a safe Rust string.
218218
pub fn name(&self) -> &'static str {
219219
// SAFETY: The id from ffi must be a proper null terminated C string
220-
let id = unsafe { CStr::from_ptr(self.to_id()) };
220+
let id = unsafe { CStr::from_ptr(self.to_id() as *const _) };
221221
id.to_str().expect("OQS algorithm names must be UTF-8")
222222
}
223223
}
@@ -282,7 +282,7 @@ impl Kem {
282282
pub fn version(&self) -> &'static str {
283283
let kem = unsafe { self.kem.as_ref() };
284284
// SAFETY: The alg_version from ffi must be a proper null terminated C string
285-
let cstr = unsafe { CStr::from_ptr(kem.alg_version) };
285+
let cstr = unsafe { CStr::from_ptr(kem.alg_version as *const _) };
286286
cstr.to_str()
287287
.expect("Algorithm version strings must be UTF-8")
288288
}

oqs/src/sig.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl Algorithm {
259259
/// This is the same as the `to_id`, but as a safe Rust string.
260260
pub fn name(&self) -> &'static str {
261261
// SAFETY: The id from ffi must be a proper null terminated C string
262-
let id = unsafe { CStr::from_ptr(self.to_id()) };
262+
let id = unsafe { CStr::from_ptr(self.to_id() as *const _) };
263263
id.to_str().expect("OQS algorithm names must be UTF-8")
264264
}
265265
}
@@ -326,7 +326,7 @@ impl Sig {
326326
pub fn version(&self) -> &'static str {
327327
let sig = unsafe { self.sig.as_ref() };
328328
// SAFETY: The alg_version from ffi must be a proper null terminated C string
329-
let cstr = unsafe { CStr::from_ptr(sig.alg_version) };
329+
let cstr = unsafe { CStr::from_ptr(sig.alg_version as *const _) };
330330
cstr.to_str()
331331
.expect("Algorithm version strings must be UTF-8")
332332
}

0 commit comments

Comments
 (0)