Skip to content

Commit

Permalink
Remove ctap-types dependency
Browse files Browse the repository at this point in the history
We only need the ctap-types for six error codes.  It makes more sense to
define these error codes directly inside the crate so that we don’t need
to make usbd-ctaphid releases just to bump ctap-types.

Arguably, this also makes the code more correct:  Previously, we used a
type that represents the CTAP2 error codes, but we actually want to use
the CTAPHID error codes.  Those happen to be the same, but it could be a
cause for confusion.

In the future, we could also use the ctaphid-types crate instead.
  • Loading branch information
robin-nitrokey committed Jun 3, 2024
1 parent 1db2e01 commit dcff900
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description = "usb-device driver for CTAPHID"
categories = ["embedded", "no-std"]

[dependencies]
ctap-types = "0.1.0"
ctaphid-dispatch = "0.1.0"
embedded-time = "0.12"
delog = "0.1.0"
Expand Down
2 changes: 0 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ pub const INTERRUPT_POLL_MILLISECONDS: u8 = 5;

pub const PACKET_SIZE: usize = 64;

// 1200
// pub const MESSAGE_SIZE: usize = ctap_types::sizes::REALISTIC_MAX_MESSAGE_SIZE;
pub const MESSAGE_SIZE: usize = 3072;
27 changes: 25 additions & 2 deletions src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use core::sync::atomic::Ordering;
use ctaphid_dispatch::command::Command;
use ctaphid_dispatch::types::Requester;

use ctap_types::Error as AuthenticatorError;
use trussed::interrupt::InterruptFlag;

use ref_swap::OptionRefSwap;
Expand All @@ -43,6 +42,30 @@ use crate::{
types::KeepaliveStatus,
};

// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#usb-hid-error
// unused variants: InvalidParameter, LockRequired, Other
enum AuthenticatorError {
ChannelBusy,
InvalidChannel,
InvalidCommand,
InvalidLength,
InvalidSeq,
Timeout,
}

impl From<AuthenticatorError> for u8 {
fn from(error: AuthenticatorError) -> Self {
match error {
AuthenticatorError::InvalidCommand => 0x01,
AuthenticatorError::InvalidLength => 0x03,
AuthenticatorError::InvalidSeq => 0x04,
AuthenticatorError::Timeout => 0x05,
AuthenticatorError::ChannelBusy => 0x06,
AuthenticatorError::InvalidChannel => 0x0B,
}
}
}

/// The actual payload of given length is dealt with separately
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Request {
Expand Down Expand Up @@ -621,7 +644,7 @@ impl<'alloc, 'pipe, 'interrupt, Bus: UsbBus> Pipe<'alloc, 'pipe, 'interrupt, Bus
}

fn start_sending_error_on_channel(&mut self, channel: u32, error: AuthenticatorError) {
self.buffer[0] = error as u8;
self.buffer[0] = error.into();
let response = Response::error_on_channel(channel);
self.start_sending(response);
}
Expand Down

0 comments on commit dcff900

Please sign in to comment.