ctaphid_app/
lib.rs

1#![no_std]
2
3use heapless_bytes::Bytes;
4use trussed_core::InterruptFlag;
5
6mod command;
7
8pub use command::{Command, VendorCommand};
9
10/// trait interface for a CTAPHID application.
11/// The application chooses which commands to register to, and will be called upon
12/// when the commands are received in the CTAPHID layer.  Only one application can be registered to a particular command.
13pub trait App<'interrupt, const N: usize> {
14    /// Get access to the app interrupter
15    fn interrupt(&self) -> Option<&'interrupt InterruptFlag> {
16        None
17    }
18
19    /// Define which CTAPHID commands to register to.
20    fn commands(&self) -> &'static [Command];
21
22    /// Application is called here when one of it's register commands occurs.
23    /// Application must put response in @message, or decide to return an error.
24    ///
25    /// The response is pre-cleared.
26    fn call(
27        &mut self,
28        command: Command,
29        request: &[u8],
30        response: &mut Bytes<N>,
31    ) -> Result<(), Error>;
32}
33
34#[derive(Copy, Clone, Debug, Eq, PartialEq)]
35pub enum Error {
36    NoResponse,
37    InvalidCommand,
38    InvalidLength,
39}