Skip to main content

fido_hid_rs/
lib.rs

1//! `fido-hid-rs` implements a minimal set of platform-specific USB HID bindings
2//! for communicating with FIDO authenticators.
3//!
4//! **Important:** this library is an _internal implementation detail_ of
5//! [webauthn-authenticator-rs][0] to work around Cargo limitations.
6//!
7//! **This library has no guarantees of API stability, and is not intended for
8//! use by other parties.**
9//!
10//! If you want to interface with USB HID FIDO authenticators, use
11//! [webauthn-authenticator-rs][0] instead of this library.
12//!
13//! If you're looking for a general-purpose Rust USB HID library, try
14//! [hidapi][].
15//!
16//! [0]: https://github.com/kanidm/webauthn-rs/tree/master/webauthn-authenticator-rs
17//! [hidapi]: https://docs.rs/hidapi/latest/hidapi/
18#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
19compile_error!("USB support is not implemented on this platform");
20
21#[cfg(target_os = "macos")]
22#[macro_use]
23extern crate core_foundation;
24
25#[cfg(target_os = "windows")]
26#[macro_use]
27extern crate lazy_static;
28
29#[macro_use]
30extern crate tracing;
31
32mod error;
33mod traits;
34
35#[cfg(any(test, target_os = "linux"))]
36mod descriptors;
37
38#[cfg_attr(target_os = "linux", path = "linux/mod.rs")]
39#[cfg_attr(target_os = "macos", path = "macos/mod.rs")]
40#[cfg_attr(target_os = "windows", path = "windows/mod.rs")]
41mod os;
42
43#[doc(inline)]
44pub use crate::{
45    error::{HidError, Result},
46    os::{USBDeviceImpl, USBDeviceInfoImpl, USBDeviceManagerImpl},
47    traits::{USBDevice, USBDeviceInfo, USBDeviceManager, WatchEvent},
48};
49
50// u2f_hid.h
51const FIDO_USAGE_PAGE: u16 = 0xf1d0;
52const FIDO_USAGE_U2FHID: u16 = 0x01;
53const HID_RPT_SIZE: usize = 64;
54const HID_RPT_SEND_SIZE: usize = HID_RPT_SIZE + 1;
55#[allow(dead_code)]
56const U2FHID_TRANS_TIMEOUT: i32 = 3000;
57
58pub type HidReportBytes = [u8; HID_RPT_SIZE];
59pub type HidSendReportBytes = [u8; HID_RPT_SEND_SIZE];