diff --git a/Cargo.toml b/Cargo.toml index a39156a..e0d64a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,8 +72,9 @@ rsa = ["trussed-rsa-alloc", "alloc"] log-all = [] log-none = [] -log-info = [] +log-trace = [] log-debug = [] +log-info = [] log-warn = [] log-error = [] diff --git a/src/lib.rs b/src/lib.rs index c69364b..03a7af5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -255,7 +255,7 @@ where } } -impl<'a, T: Client> LoadedAuthenticator<'a, T> { +impl LoadedAuthenticator<'_, T> { pub fn yubico_set_administration_key( &mut self, data: &[u8], diff --git a/src/reply.rs b/src/reply.rs index 74101c3..ebca2a3 100644 --- a/src/reply.rs +++ b/src/reply.rs @@ -12,13 +12,13 @@ impl<'v, const R: usize> Deref for Reply<'v, R> { } } -impl<'v, const R: usize> DerefMut for Reply<'v, R> { +impl DerefMut for Reply<'_, R> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } -impl<'v, const R: usize> Reply<'v, R> { +impl Reply<'_, R> { /// Extend the reply and return an error otherwise /// The MoreAvailable and GET RESPONSE mechanisms are handled by adpu_dispatch /// diff --git a/src/state.rs b/src/state.rs index 99b2047..4b07270 100644 --- a/src/state.rs +++ b/src/state.rs @@ -305,7 +305,7 @@ impl Drop for UseValidKey { } } -impl<'t> LoadedState<'t> { +impl LoadedState<'_> { pub fn key_exists( &self, client: &mut impl crate::Client, diff --git a/tests/command_response.rs b/tests/command_response.rs index de73fab..de45f8b 100644 --- a/tests/command_response.rs +++ b/tests/command_response.rs @@ -648,7 +648,7 @@ impl IoCmd { let mut random_challenge = vec![0; alg.challenge_len()]; thread_rng().fill_bytes(&mut random_challenge); let challenge_and_random: Vec = - [tlv(&[0x80], &challenge), tlv(&[0x81], &random_challenge)] + [tlv(&[0x80], challenge), tlv(&[0x81], &random_challenge)] .into_iter() .flatten() .collect(); diff --git a/tests/pivy.rs b/tests/pivy.rs index d5a2dab..2f10460 100644 --- a/tests/pivy.rs +++ b/tests/pivy.rs @@ -8,9 +8,37 @@ use cfg_if::cfg_if; use expectrl::{spawn, Eof, Regex, WaitStatus}; use std::io::{self, Read, Write}; -use std::process::{Command, Stdio}; +use std::ops::{Deref, DerefMut}; +use std::process::{Child, Command, ExitStatus, Stdio}; use std::time::Duration; +pub struct CommandWrapper(pub Child); + +impl Deref for CommandWrapper { + type Target = Child; + fn deref(&self) -> &Child { + &self.0 + } +} + +impl DerefMut for CommandWrapper { + fn deref_mut(&mut self) -> &mut Child { + &mut self.0 + } +} + +impl CommandWrapper { + pub fn wait(&mut self) -> io::Result { + self.0.wait() + } +} + +impl Drop for CommandWrapper { + fn drop(&mut self) { + self.0.wait().ok(); + } +} + const CARD: &str = env!("PIV_DANGEROUS_TEST_CARD_READER"); const EXPECT_TIMEOUT: Option = Some(Duration::from_secs(30)); @@ -128,16 +156,18 @@ fn ecdh_inner(key: &str, requires_pin: bool) { WaitStatus::Exited(p.get_process().pid(), 0) ); - let mut p = Command::new("pivy-tool") - .args(if requires_pin { - vec!["sign", key, "-P", "123456"] - } else { - vec!["sign", key] - }) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .unwrap(); + let mut p = CommandWrapper( + Command::new("pivy-tool") + .args(if requires_pin { + vec!["sign", key, "-P", "123456"] + } else { + vec!["sign", key] + }) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .unwrap(), + ); let mut stdin = p.stdin.take().unwrap(); write!(stdin, "ecdsa-sha2-nistp256 \ @@ -190,16 +220,18 @@ fn sign_inner(key: &str, requires_pin: bool) { WaitStatus::Exited(p.get_process().pid(), 0) ); - let mut p = Command::new("pivy-tool") - .args(if requires_pin { - vec!["sign", key, "-P", "123456"] - } else { - vec!["sign", key] - }) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .unwrap(); + let mut p = CommandWrapper( + Command::new("pivy-tool") + .args(if requires_pin { + vec!["sign", key, "-P", "123456"] + } else { + vec!["sign", key] + }) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .unwrap(), + ); let mut stdin = p.stdin.take().unwrap(); write!(stdin, "data").unwrap(); drop(stdin); @@ -220,16 +252,18 @@ fn sign_inner(key: &str, requires_pin: bool) { WaitStatus::Exited(p.get_process().pid(), 0) ); - let mut p = Command::new("pivy-tool") - .args(if requires_pin { - vec!["sign", key, "-P", "123456"] - } else { - vec!["sign", key] - }) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .unwrap(); + let mut p = CommandWrapper( + Command::new("pivy-tool") + .args(if requires_pin { + vec!["sign", key, "-P", "123456"] + } else { + vec!["sign", key] + }) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .unwrap(), + ); let mut stdin = p.stdin.take().unwrap(); let mut stdout = p.stdout.take().unwrap(); write!(stdin, "data").unwrap(); @@ -326,12 +360,14 @@ N4vF6RP8Ck9wj1OYq/w82MkgxOPleUju4Q== #[test_log::test] fn large_cert() { let test = || { - let mut p = Command::new("pivy-tool") - .args(["write-cert", "9A"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .unwrap(); + let mut p = CommandWrapper( + Command::new("pivy-tool") + .args(["write-cert", "9A"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .unwrap(), + ); let mut stdin = p.stdin.take().unwrap(); stdin.write_all(LARGE_CERT.as_bytes()).unwrap(); drop(stdin);