Fix clippy warnings

This commit is contained in:
Sosthène Guédon
2025-03-06 09:55:34 +01:00
committed by sosthene-nitrokey
parent ca9b10f9c9
commit b8a496f67c
6 changed files with 80 additions and 43 deletions
+2 -1
View File
@@ -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 = []
+1 -1
View File
@@ -255,7 +255,7 @@ where
}
}
impl<'a, T: Client> LoadedAuthenticator<'a, T> {
impl<T: Client> LoadedAuthenticator<'_, T> {
pub fn yubico_set_administration_key<const R: usize>(
&mut self,
data: &[u8],
+2 -2
View File
@@ -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<const R: usize> DerefMut for Reply<'_, R> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<'v, const R: usize> Reply<'v, R> {
impl<const R: usize> Reply<'_, R> {
/// Extend the reply and return an error otherwise
/// The MoreAvailable and GET RESPONSE mechanisms are handled by adpu_dispatch
///
+1 -1
View File
@@ -305,7 +305,7 @@ impl Drop for UseValidKey {
}
}
impl<'t> LoadedState<'t> {
impl LoadedState<'_> {
pub fn key_exists(
&self,
client: &mut impl crate::Client,
+1 -1
View File
@@ -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<u8> =
[tlv(&[0x80], &challenge), tlv(&[0x81], &random_challenge)]
[tlv(&[0x80], challenge), tlv(&[0x81], &random_challenge)]
.into_iter()
.flatten()
.collect();
+73 -37
View File
@@ -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<ExitStatus> {
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<Duration> = 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);