Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ fuzz/corpus/
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

# Editor files
.vscode

.DS_Store
12 changes: 3 additions & 9 deletions src/transport/hidproto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use std::io;
use std::mem;

use byteorder::{LittleEndian, ReadBytesExt};

use crate::consts::{FIDO_USAGE_PAGE, FIDO_USAGE_U2FHID};
#[cfg(target_os = "linux")]
use crate::consts::{INIT_HEADER_SIZE, MAX_HID_RPT_SIZE};
Expand Down Expand Up @@ -84,7 +86,7 @@ impl ReportDescriptorIterator {
assert!(data.len() <= mem::size_of::<u32>());

// Convert data bytes to a uint.
let data = read_uint_le(data);
let data = data.read_u8::<LittleEndian>().unwrap();
match tag_type {
HID_ITEM_TAGTYPE_USAGE_PAGE => Some(Data::UsagePage { data }),
HID_ITEM_TAGTYPE_USAGE => Some(Data::Usage { data }),
Expand Down Expand Up @@ -152,14 +154,6 @@ fn get_hid_short_item<'a>(buf: &'a [u8]) -> Option<(u8, usize, &'a [u8])> {
))
}

fn read_uint_le(buf: &[u8]) -> u32 {
assert!(buf.len() <= 4);
// Parse the number in little endian byte order.
buf.iter()
.rev()
.fold(0, |num, b| (num << 8) | (u32::from(*b)))
}

pub fn has_fido_usage(desc: ReportDescriptor) -> bool {
let mut usage_page = None;
let mut usage = None;
Expand Down