feat(rust): add memory compare implementation
use std::alloc::Layout;
use std::mem;
use std::ptr;
+use libc::memcmp;
use ockam_vault_sys::{ockam_error_t, ockam_memory_dispatch_table_t, ockam_memory_t};
@@ -21,6 +22,7 @@ impl RustAlloc {
set: Some(self::memset_impl),
copy: Some(self::memcpy_impl),
move_: Some(self::memmove_impl),
+ compare: Some(self::memcmp_impl),
};
const GLOBAL: Self = Self {
@@ -92,3 +94,19 @@ unsafe extern "C" fn memmove_impl(
core::intrinsics::copy(src, dst, size);
ockam_vault_sys::OCKAM_ERROR_NONE
}
+
+unsafe extern "C" fn memcmp_impl(
+ _: *mut ockam_memory_t,
+ res: *mut i32,
+ lhs: *const core::ffi::c_void,
+ rhs: *const core::ffi::c_void,
+ size: usize,
+) -> ockam_error_t {
+ if res.is_null() || lhs.is_null() || rhs.is_null() {
+ return ockam_vault_sys::OCKAM_MEMORY_ERROR_INVALID_PARAM;
+ }
+
+ *res = memcmp(lhs, rhs, size);
+
+ ockam_vault_sys::OCKAM_ERROR_NONE
+}
