diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-09-22 18:26:53 +0200 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2020-09-22 18:26:53 +0200 |
commit | 4932d2376cc03c64eb82972824be673cdc2e0741 (patch) | |
tree | d1690533683e8fe33be00e4b1eb32f9363f207b4 | |
parent | 7944af959ca0b48f0e8ea5c506e801e07a6b8124 (diff) | |
download | nitrokey-sys-rs-4932d2376cc03c64eb82972824be673cdc2e0741.tar.gz nitrokey-sys-rs-4932d2376cc03c64eb82972824be673cdc2e0741.tar.bz2 |
Do not include layout tests in generated bindings
We are generating the Rust bindings in src/ffi.rs using bindgen once for
all platforms on an amd64 machine. These bindings previously included
layout tests. But these tests fail on some 32-bit architecture. See
this discussion for more information:
https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20200919182408.GA1513%40ireas.org%3E
With this patch, we remove the layout tests from the generated bindings.
Instead, we will add the option to re-generate the bindings, including
the layout tests, during the build in the next patch.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | patches/deprecated.diff | 8 | ||||
-rw-r--r-- | src/ffi.rs | 689 |
4 files changed, 6 insertions, 693 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index af7fb18..8efd48c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Derive `Debug` for all structs generated by `bindgen`. - Implement `std::fmt::Display` instead of `std::string::ToString` for the `Version` enum in `build.rs`. +- Do not include layout tests in the generated bindings. - Update to libnitrokey 3.6, causing all following changes. - New constants: - `NK_device_model_NK_LIBREM` (`NK_device_model` enum) @@ -8,6 +8,7 @@ src/ffi.rs: ${LIBNITROKEY}/NK_C_API.h --whitelist-var "NK_.*" \ --whitelist-var "MAXIMUM_STR_REPLY_LENGTH" \ --with-derive-default \ + --no-layout-tests \ --output "$@" \ "$<" \ -- "-I${LIBNITROKEY}/libnitrokey" diff --git a/patches/deprecated.diff b/patches/deprecated.diff index 79fe5ba..e13f90f 100644 --- a/patches/deprecated.diff +++ b/patches/deprecated.diff @@ -6,7 +6,7 @@ Index: nitrokey-sys-rs/src/ffi.rs =================================================================== --- nitrokey-sys-rs.orig/src/ffi.rs +++ nitrokey-sys-rs/src/ffi.rs -@@ -848,6 +848,7 @@ extern "C" { +@@ -212,6 +212,7 @@ extern "C" { #[doc = " deprecated in favor of NK_get_status_as_string."] #[doc = " @return string representation of the status or an empty string"] #[doc = " if the command failed"] @@ -14,7 +14,7 @@ Index: nitrokey-sys-rs/src/ffi.rs pub fn NK_status() -> *mut ::std::os::raw::c_char; } extern "C" { -@@ -1134,6 +1135,7 @@ extern "C" { +@@ -498,6 +499,7 @@ extern "C" { pub fn NK_totp_set_time_soft(time: u64) -> ::std::os::raw::c_int; } extern "C" { @@ -22,7 +22,7 @@ Index: nitrokey-sys-rs/src/ffi.rs pub fn NK_totp_get_time() -> ::std::os::raw::c_int; } extern "C" { -@@ -1309,6 +1311,7 @@ extern "C" { +@@ -673,6 +675,7 @@ extern "C" { #[doc = " Storage only"] #[doc = " @param user_pin 20 characters User PIN"] #[doc = " @return command processing error code"] @@ -30,7 +30,7 @@ Index: nitrokey-sys-rs/src/ffi.rs pub fn NK_set_unencrypted_read_only( user_pin: *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; -@@ -1322,6 +1325,7 @@ extern "C" { +@@ -686,6 +689,7 @@ extern "C" { #[doc = " Storage only"] #[doc = " @param user_pin 20 characters User PIN"] #[doc = " @return command processing error code"] @@ -28,59 +28,6 @@ pub struct NK_device_info { #[doc = " if this is the last element in the list."] pub next: *mut NK_device_info, } -#[test] -fn bindgen_test_layout_NK_device_info() { - assert_eq!( - ::std::mem::size_of::<NK_device_info>(), - 32usize, - concat!("Size of: ", stringify!(NK_device_info)) - ); - assert_eq!( - ::std::mem::align_of::<NK_device_info>(), - 8usize, - concat!("Alignment of ", stringify!(NK_device_info)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_device_info>())).model as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(model) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_device_info>())).path as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(path) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_device_info>())).serial_number as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(serial_number) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_device_info>())).next as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(next) - ) - ); -} impl Default for NK_device_info { fn default() -> Self { unsafe { ::std::mem::zeroed() } @@ -112,95 +59,6 @@ pub struct NK_status { #[doc = " an OTP value."] pub otp_user_password: bool, } -#[test] -fn bindgen_test_layout_NK_status() { - assert_eq!( - ::std::mem::size_of::<NK_status>(), - 12usize, - concat!("Size of: ", stringify!(NK_status)) - ); - assert_eq!( - ::std::mem::align_of::<NK_status>(), - 4usize, - concat!("Alignment of ", stringify!(NK_status)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_status>())).firmware_version_major as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(firmware_version_major) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_status>())).firmware_version_minor as *const _ as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(firmware_version_minor) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_status>())).serial_number_smart_card as *const _ as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(serial_number_smart_card) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_status>())).config_numlock as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_numlock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_status>())).config_capslock as *const _ as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_capslock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_status>())).config_scrolllock as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_scrolllock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_status>())).otp_user_password as *const _ as usize }, - 11usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(otp_user_password) - ) - ); -} #[doc = " Stores the status of a Storage device."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -239,219 +97,6 @@ pub struct NK_storage_status { #[doc = " the AES keys."] pub stick_initialized: bool, } -#[test] -fn bindgen_test_layout_NK_storage_status() { - assert_eq!( - ::std::mem::size_of::<NK_storage_status>(), - 28usize, - concat!("Size of: ", stringify!(NK_storage_status)) - ); - assert_eq!( - ::std::mem::align_of::<NK_storage_status>(), - 4usize, - concat!("Alignment of ", stringify!(NK_storage_status)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).unencrypted_volume_read_only as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(unencrypted_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).unencrypted_volume_active as *const _ - as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(unencrypted_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).encrypted_volume_read_only as *const _ - as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(encrypted_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).encrypted_volume_active as *const _ - as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(encrypted_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).hidden_volume_read_only as *const _ - as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(hidden_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).hidden_volume_active as *const _ as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(hidden_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).firmware_version_major as *const _ - as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_version_major) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).firmware_version_minor as *const _ - as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_version_minor) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).firmware_locked as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_locked) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).serial_number_sd_card as *const _ as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(serial_number_sd_card) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).serial_number_smart_card as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(serial_number_smart_card) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).user_retry_count as *const _ as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(user_retry_count) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).admin_retry_count as *const _ as usize - }, - 21usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(admin_retry_count) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).new_sd_card_found as *const _ as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(new_sd_card_found) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).filled_with_random as *const _ as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(filled_with_random) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_status>())).stick_initialized as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(stick_initialized) - ) - ); -} #[doc = " Data about the usage of the SD card."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -463,43 +108,6 @@ pub struct NK_SD_usage_data { #[doc = " size."] pub write_level_max: u8, } -#[test] -fn bindgen_test_layout_NK_SD_usage_data() { - assert_eq!( - ::std::mem::size_of::<NK_SD_usage_data>(), - 2usize, - concat!("Size of: ", stringify!(NK_SD_usage_data)) - ); - assert_eq!( - ::std::mem::align_of::<NK_SD_usage_data>(), - 1usize, - concat!("Alignment of ", stringify!(NK_SD_usage_data)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_SD_usage_data>())).write_level_min as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_SD_usage_data), - "::", - stringify!(write_level_min) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_SD_usage_data>())).write_level_max as *const _ as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_SD_usage_data), - "::", - stringify!(write_level_max) - ) - ); -} #[doc = " The general configuration of a Nitrokey device."] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -516,69 +124,6 @@ pub struct NK_config { #[doc = " Unused."] pub disable_user_password: bool, } -#[test] -fn bindgen_test_layout_NK_config() { - assert_eq!( - ::std::mem::size_of::<NK_config>(), - 5usize, - concat!("Size of: ", stringify!(NK_config)) - ); - assert_eq!( - ::std::mem::align_of::<NK_config>(), - 1usize, - concat!("Alignment of ", stringify!(NK_config)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_config>())).numlock as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(numlock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_config>())).capslock as *const _ as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(capslock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_config>())).scrolllock as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(scrolllock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_config>())).enable_user_password as *const _ as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(enable_user_password) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<NK_config>())).disable_user_password as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_config), - "::", - stringify!(disable_user_password) - ) - ); -} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NK_storage_ProductionTest { @@ -596,187 +141,6 @@ pub struct NK_storage_ProductionTest { pub SD_WriteSpeed_u16: u16, pub SD_Card_Manufacturer_u8: u8, } -#[test] -fn bindgen_test_layout_NK_storage_ProductionTest() { - assert_eq!( - ::std::mem::size_of::<NK_storage_ProductionTest>(), - 28usize, - concat!("Size of: ", stringify!(NK_storage_ProductionTest)) - ); - assert_eq!( - ::std::mem::align_of::<NK_storage_ProductionTest>(), - 4usize, - concat!("Alignment of ", stringify!(NK_storage_ProductionTest)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).FirmwareVersion_au8 as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(FirmwareVersion_au8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).FirmwareVersionInternal_u8 - as *const _ as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(FirmwareVersionInternal_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SD_Card_Size_u8 as *const _ - as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_Size_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).CPU_CardID_u32 as *const _ - as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(CPU_CardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SmartCardID_u32 as *const _ - as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SmartCardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SD_CardID_u32 as *const _ as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_CardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SC_UserPwRetryCount as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SC_UserPwRetryCount) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SC_AdminPwRetryCount as *const _ - as usize - }, - 17usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SC_AdminPwRetryCount) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SD_Card_ManufacturingYear_u8 - as *const _ as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_ManufacturingYear_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SD_Card_ManufacturingMonth_u8 - as *const _ as usize - }, - 19usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_ManufacturingMonth_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SD_Card_OEM_u16 as *const _ - as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_OEM_u16) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SD_WriteSpeed_u16 as *const _ - as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_WriteSpeed_u16) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<NK_storage_ProductionTest>())).SD_Card_Manufacturer_u8 - as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_Manufacturer_u8) - ) - ); -} extern "C" { pub fn NK_get_storage_production_info( out: *mut NK_storage_ProductionTest, @@ -1548,59 +912,6 @@ pub struct ReadSlot_t { pub slot_token_id: [u8; 13usize], pub slot_counter: u64, } -#[test] -fn bindgen_test_layout_ReadSlot_t() { - assert_eq!( - ::std::mem::size_of::<ReadSlot_t>(), - 40usize, - concat!("Size of: ", stringify!(ReadSlot_t)) - ); - assert_eq!( - ::std::mem::align_of::<ReadSlot_t>(), - 8usize, - concat!("Alignment of ", stringify!(ReadSlot_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<ReadSlot_t>())).slot_name as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_name) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<ReadSlot_t>()))._slot_config as *const _ as usize }, - 15usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(_slot_config) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<ReadSlot_t>())).slot_token_id as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_token_id) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<ReadSlot_t>())).slot_counter as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_counter) - ) - ); -} extern "C" { pub fn NK_read_HOTP_slot(slot_num: u8, out: *mut ReadSlot_t) -> ::std::os::raw::c_int; } |