Expand description
USB-HID protocol used between the mini-HSM dongle and the host.
This crate is no_std by default so the firmware can depend on it. The
std feature toggles a handful of niceties (currently nothing, kept as
a future extension point).
§Wire format
Every exchange consists of fixed-size HID reports of HID_REPORT_SIZE
bytes. The same 3-byte header is used in both directions:
Byte 0 : Opcode (command opcode for IN reports, status byte for OUT)
Byte 1..3 : Payload length, little-endian u16
Byte 3..3+len : Payload
Byte 3+len..end : Zero padding (sent zero, ignored on receive)len is the host-meaningful payload size, not the wire size. The wire
size is always HID_REPORT_SIZE regardless. len must not exceed
MAX_PAYLOAD_SIZE.
§Layering
Frame encodes/decodes the byte layout. It is opcode-agnostic and
deals only with (u8, &[u8]). Both the firmware and hsm-host build
one Frame per HID report, then interpret the payload with helpers
defined in commands and responses. There is no big enum Command { Info, Sign { slot, digest }, ... }: that pattern scales
poorly with size and pays runtime cost for static information.
Re-exports§
pub use commands::CommandOpcode;pub use frame::Frame;pub use frame::FrameParseError;pub use responses::ResponseStatus;
Modules§
- commands
- Commands sent from the host to the token.
- frame
- Byte-level encoding and decoding of HID frames.
- hid_
descriptor 🔒 - HID report descriptor for the mini-HSM.
- responses
- Status bytes returned by the token in every response report.
Constants§
- HEADER_
SIZE 🔒 - Size of the 3-byte header (
opcode | len_lo | len_hi). - HID_
REPORT_ DESCRIPTOR - HID report descriptor, exactly as sent to the host during USB enumeration.
- HID_
REPORT_ SIZE - Fixed size of every HID report in either direction.
- MAX_
PAYLOAD_ 🔒SIZE - Maximum payload size in a report (
HID_REPORT_SIZE-HEADER_SIZE). - USB_PID
- USB product identifier for this project.
- USB_VID
- USB vendor identifier for this project.
0xCAFEis a community convention for open-source / hobby devices (no USB-IF assignment).