diff --git a/.gitignore b/.gitignore index 148e97ce..530a1910 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/transport/hidproto.rs b/src/transport/hidproto.rs index 5a0a9d26..4a7c9759 100644 --- a/src/transport/hidproto.rs +++ b/src/transport/hidproto.rs @@ -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}; @@ -84,7 +86,7 @@ impl ReportDescriptorIterator { assert!(data.len() <= mem::size_of::()); // Convert data bytes to a uint. - let data = read_uint_le(data); + let data = data.read_u8::().unwrap(); match tag_type { HID_ITEM_TAGTYPE_USAGE_PAGE => Some(Data::UsagePage { data }), HID_ITEM_TAGTYPE_USAGE => Some(Data::Usage { data }), @@ -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;