From 4b436755d5895cb7113bee135d451cdeb2cf465a Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 20 Feb 2019 12:31:45 +0000 Subject: Assert maximum size for command request and response structs The request and response structs for a command should not be bigger than the buffer they are read from or written to. Therefore we add assertions that enforce this property at compile time. --- src/commands.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/commands.rs') diff --git a/src/commands.rs b/src/commands.rs index 99e049f..66851c1 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -34,6 +34,8 @@ struct GetStatusResponse { config_delete_user_password: u8, } +assert_maximum_size!(GetStatusResponse; GetStatusResponse, crate::device::RESPONSE_DATA_LEN); + #[derive(Debug, Default)] struct GetStatusCommand {} @@ -53,11 +55,15 @@ struct ReadSlotNameRequest { internal_slot_number: u8, } +assert_maximum_size!(ReadSlotNameRequest; ReadSlotNameRequest, crate::device::REQUEST_DATA_LEN); + #[derive(Debug, Default, Serialize)] struct ReadSlotNameResponse { slot_name: [u8; 15], } +assert_maximum_size!(ReadSlotNameResponse; ReadSlotNameResponse, crate::device::RESPONSE_DATA_LEN); + #[derive(Debug, Default)] struct ReadSlotNameCommand {} -- cgit v1.2.1