diff --git a/src/apps/oath.rs b/src/apps/oath.rs index 9f32042..f69236d 100644 --- a/src/apps/oath.rs +++ b/src/apps/oath.rs @@ -195,7 +195,7 @@ impl Credential { pub fn id(&self) -> String { let mut id = String::new(); if let Kind::Totp(totp) = self.kind { - if totp != Default::default() { + if totp != Totp::default() { write!(id, "{}/", totp.period).ok(); } } @@ -325,7 +325,7 @@ impl Decodable<'_> for Tag { impl App<'_> { /// Returns the credential ID. - pub fn register(&mut self, credential: Credential) -> Result { + pub fn register(&mut self, credential: &Credential) -> Result { info!(" registering credential {:?}", &credential); // data = Tlv(TAG_NAME, cred_id) + Tlv( // TAG_KEY, @@ -409,7 +409,7 @@ impl App<'_> { assert_eq!(response[1], 5); let digits = response[2] as usize; let truncated_code = u32::from_be_bytes(response[3..].try_into().unwrap()); - let code = (truncated_code & 0x7FFFFFFF) % 10u32.pow(digits as _); + let code = (truncated_code & 0x7FFF_FFFF) % 10u32.pow(digits as _); Ok(format!("{:0digits$}", code, digits = digits)) } diff --git a/src/bin/solo2/main.rs b/src/bin/solo2/main.rs index fab7798..3ebff04 100644 --- a/src/bin/solo2/main.rs +++ b/src/bin/solo2/main.rs @@ -179,7 +179,7 @@ fn try_main(args: cli::Cli) -> anyhow::Result<()> { algorithm: digest, digits: args.digits, }; - let credential_id = app.register(credential)?; + let credential_id = app.register(&credential)?; println!("{}", credential_id); Ok(()) } diff --git a/src/device.rs b/src/device.rs index 53ac1b5..1983405 100644 --- a/src/device.rs +++ b/src/device.rs @@ -123,22 +123,22 @@ impl UuidSelectable for Solo2 { fn list() -> Vec { // iterator/lifetime woes avoiding the explicit for loop let mut ctaps = BTreeMap::new(); - for mut device in ctap::list().into_iter() { + for mut device in ctap::list() { if let Ok(uuid) = device.try_uuid() { ctaps.insert(uuid, device); } } // iterator/lifetime woes avoiding the explicit for loop let mut pcscs = BTreeMap::new(); - for mut device in pcsc::list().into_iter() { + for mut device in pcsc::list() { if let Ok(uuid) = device.try_uuid() { pcscs.insert(uuid, device); } } - let uuids = BTreeSet::from_iter(ctaps.keys().chain(pcscs.keys()).copied()); + let uuids: BTreeSet = ctaps.keys().chain(pcscs.keys()).copied().collect(); let mut devices = Vec::new(); - for uuid in uuids.iter() { + for uuid in &uuids { // a bit roundabout, but hey, "it works". let mut device = Self { ctap: ctaps.remove(uuid), diff --git a/src/device/ctap.rs b/src/device/ctap.rs index 2d6607d..fa3ec3b 100644 --- a/src/device/ctap.rs +++ b/src/device/ctap.rs @@ -43,9 +43,7 @@ pub struct Device { } pub fn list() -> Vec { - Session::new() - .map(|session| session.devices()) - .unwrap_or_else(|_| vec![]) + Session::new().map_or_else(|_| vec![], |session| session.devices()) } impl From for Info { diff --git a/src/device/pcsc.rs b/src/device/pcsc.rs index 348bab5..c9813ae 100644 --- a/src/device/pcsc.rs +++ b/src/device/pcsc.rs @@ -50,9 +50,7 @@ pub struct Device { } pub fn list() -> Vec { - Session::new() - .map(|session| session.devices()) - .unwrap_or_else(|_| vec![]) + Session::new().map_or_else(|_| vec![], |session| session.devices()) } impl Session { diff --git a/src/firmware.rs b/src/firmware.rs index 7bce386..17dd232 100644 --- a/src/firmware.rs +++ b/src/firmware.rs @@ -26,11 +26,7 @@ impl Firmware { // pub fn verify(&self) -> Result<()> { // } - pub fn write_to<'a>( - &self, - bootloader: &lpc55::Bootloader, - progress: Option<&'a dyn Fn(usize)>, - ) { + pub fn write_to(&self, bootloader: &lpc55::Bootloader, progress: Option<&dyn Fn(usize)>) { bootloader.receive_sb_file(&self.content, progress); } diff --git a/src/transport.rs b/src/transport.rs index 1613407..73f6dbd 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -33,7 +33,7 @@ impl Transport for ctap::Device { use ctap::{Code, Command}; let init = self.init()?; let command = Command::new(Code::from(instruction)).with_data(data); - ctap::Device::call(self, init.channel, command) + ctap::Device::call(self, init.channel, &command) } fn call_iso(&mut self, _: u8, _: u8, _: u8, _: u8, _: &[u8]) -> Result> { diff --git a/src/transport/ctap.rs b/src/transport/ctap.rs index 1c1b78c..69943ab 100644 --- a/src/transport/ctap.rs +++ b/src/transport/ctap.rs @@ -186,7 +186,7 @@ impl Channel { } impl Device { - pub fn call(&self, channel: Channel, request: Command) -> Result> { + pub fn call(&self, channel: Channel, request: &Command) -> Result> { let result: Result> = request .packets(channel) .enumerate() @@ -260,7 +260,7 @@ impl Device { getrandom::getrandom(&mut nonce).unwrap(); // dbg!(hex::encode(&nonce)); let command = Command::new(Code::Init).with_data(&nonce); - let response = self.call(Channel::BROADCAST, command)?; + let response = self.call(Channel::BROADCAST, &command)?; // let mut packet = [0u8; 64]; // let read = self.device.read(&mut packet)?; assert_eq!(response.len(), 17); @@ -286,7 +286,7 @@ impl Device { pub fn ping(&self, channel: Channel, data: &[u8]) -> Result> { let command = Command::new(Code::Ping).with_data(data); - let response = self.call(channel, command)?; + let response = self.call(channel, &command)?; assert_eq!(data, response); Ok(response) @@ -294,7 +294,7 @@ impl Device { pub fn wink(&self, channel: Channel) -> Result> { let command = Command::new(Code::Wink); - let response = self.call(channel, command)?; + let response = self.call(channel, &command)?; Ok(response) } }