From f11fdcbc62d06b8be23e6cbae21bcfefd52c0661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Fri, 29 Aug 2025 11:00:29 +0200 Subject: [PATCH] Update to heapless 0.9 --- Cargo.toml | 3 ++- app/src/lib.rs | 6 +++--- dispatch/src/dispatch.rs | 15 +++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8f29ba1..2bbadcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,9 @@ license = "Apache-2.0 OR MIT" repository = "https://github.com/solokeys/ctaphid-dispatch" [workspace.dependencies] -heapless-bytes = "0.3" +heapless-bytes = "0.5" trussed-core = "0.1.0" [patch.crates-io] ctaphid-app.path = "app" +trussed-core = { git = "https://github.com/trussed-dev/trussed.git", rev = "1e7b09a983dc8ae64a7ad8401ce541a9a77e5939"} diff --git a/app/src/lib.rs b/app/src/lib.rs index d161fa2..9f93ba7 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] -use heapless_bytes::Bytes; +use heapless_bytes::BytesView; use trussed_core::InterruptFlag; mod command; @@ -10,7 +10,7 @@ pub use command::{Command, VendorCommand}; /// trait interface for a CTAPHID application. /// The application chooses which commands to register to, and will be called upon /// when the commands are received in the CTAPHID layer. Only one application can be registered to a particular command. -pub trait App<'interrupt, const N: usize> { +pub trait App<'interrupt> { /// Get access to the app interrupter fn interrupt(&self) -> Option<&'interrupt InterruptFlag> { None @@ -27,7 +27,7 @@ pub trait App<'interrupt, const N: usize> { &mut self, command: Command, request: &[u8], - response: &mut Bytes, + response: &mut BytesView, ) -> Result<(), Error>; } diff --git a/dispatch/src/dispatch.rs b/dispatch/src/dispatch.rs index a5d6e3a..63eb7d8 100644 --- a/dispatch/src/dispatch.rs +++ b/dispatch/src/dispatch.rs @@ -34,8 +34,8 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> { fn find_app<'a, 'b>( command: Command, - apps: &'a mut [&'b mut dyn App<'interrupt, N>], - ) -> Option<&'a mut &'b mut dyn App<'interrupt, N>> { + apps: &'a mut [&'b mut dyn App<'interrupt>], + ) -> Option<&'a mut &'b mut dyn App<'interrupt>> { apps.iter_mut() .find(|app| app.commands().contains(&command)) } @@ -75,7 +75,7 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> { } #[inline(never)] - fn call_app(&mut self, app: &mut dyn App<'interrupt, N>, command: Command, request: &Bytes) { + fn call_app(&mut self, app: &mut dyn App<'interrupt>, command: Command, request: &[u8]) { let response_buffer = self .responder .response_mut() @@ -106,18 +106,17 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> { } #[inline(never)] - pub fn poll(&mut self, apps: &mut [&mut dyn App<'interrupt, N>]) -> bool { + pub fn poll(&mut self, apps: &mut [&mut dyn App<'interrupt>]) -> bool { // We could call take_request directly, but for some reason this doubles stack usage. - let mut message_buffer = Bytes::new(); + let mut buffer = Bytes::::new(); if let Ok((command, message)) = self.responder.request() { // info_now!("cmd: {}", u8::from(command)); // info_now!("cmd: {:?}", command); - message_buffer.extend_from_slice(message).unwrap(); - + buffer.extend_from_slice(message).unwrap(); if let Some(app) = Self::find_app(*command, apps) { // match app.call(command, self.responder.response_mut().unwrap()) { - self.call_app(*app, *command, &message_buffer); + self.call_app(*app, *command, &buffer); } else { self.reply_with_error(Error::InvalidCommand); }