diff --git a/src/hid_linux.rs b/src/hid_linux.rs index b04e75c..6d6ff44 100644 --- a/src/hid_linux.rs +++ b/src/hid_linux.rs @@ -16,11 +16,12 @@ static USAGE_PAGE: u8 = 0x04; static USAGE: u8 = 0x08; static REPORT_SIZE: u8 = 0x74; -pub fn enumerate() -> io::Result> { - fs::read_dir("/sys/class/hidraw")? - .filter_map(|entry| entry.ok()) - .map(|entry| path_to_device(&entry.path())) - .collect() +pub fn enumerate() -> io::Result> { + fs::read_dir("/sys/class/hidraw").map(|entries| { + entries.filter_map(|entry| entry.ok()).filter_map(|entry| { + path_to_device(&entry.path()).ok() + }) + }) } fn path_to_device(path: &PathBuf) -> io::Result { diff --git a/src/lib.rs b/src/lib.rs index 47e8854..0f89b73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,8 +10,8 @@ //! //! ``` //! # fn do_fido() -> ctap::FidoResult<()> { -//! let devices = ctap::get_devices()?; -//! let device_info = &devices[0]; +//! let mut devices = ctap::get_devices()?; +//! let device_info = &devices.next().unwrap(); //! let mut device = ctap::FidoDevice::new(device_info)?; //! //! // This can be omitted if the FIDO device is not configured with a PIN. @@ -74,14 +74,13 @@ pub use self::error::*; static BROADCAST_CID: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; /// Looks for any connected HID devices and returns those that support FIDO. -pub fn get_devices() -> error::FidoResult> { - Ok( - hid::enumerate() - .context(FidoErrorKind::Io)? - .into_iter() - .filter(|dev| dev.usage_page == 0xf1d0 && dev.usage == 0x21) - .collect(), - ) +pub fn get_devices() -> FidoResult> { + hid::enumerate() + .context(FidoErrorKind::Io) + .map(|devices| { + devices.filter(|dev| dev.usage_page == 0xf1d0 && dev.usage == 0x21) + }) + .map_err(From::from) } /// A credential created by a FIDO2 authenticator.