fido_authenticator/dispatch/
ctaphid.rs

1use ctaphid_app::{App, Command, Error};
2use heapless_bytes::Bytes;
3use trussed_core::InterruptFlag;
4
5#[allow(unused_imports)]
6use crate::msp;
7use crate::{Authenticator, TrussedRequirements, UserPresence};
8
9impl<UP, T, const N: usize> App<'static, N> for Authenticator<UP, T>
10where
11    UP: UserPresence,
12    T: TrussedRequirements,
13{
14    fn commands(&self) -> &'static [Command] {
15        &[Command::Cbor, Command::Msg]
16    }
17
18    #[inline(never)]
19    fn call(
20        &mut self,
21        command: Command,
22        request: &[u8],
23        response: &mut Bytes<N>,
24    ) -> Result<(), Error> {
25        debug_now!(
26            "ctaphid-dispatch: remaining stack: {} bytes",
27            msp() - 0x2000_0000
28        );
29
30        if request.is_empty() {
31            debug_now!("invalid request length in ctaphid.call");
32            return Err(Error::InvalidLength);
33        }
34
35        // info_now!("request: ");
36        // blocking::dump_hex(request, request.len());
37        match command {
38            Command::Cbor => super::handle_ctap2(self, request, response),
39            Command::Msg => super::handle_ctap1_from_hid(self, request, response),
40            _ => {
41                debug_now!("ctaphid trying to dispatch {:?}", command);
42            }
43        };
44        Ok(())
45    }
46
47    fn interrupt(&self) -> Option<&'static InterruptFlag> {
48        self.trussed.interrupt()
49    }
50}