Fix clippy warnings

This commit is contained in:
Sosthène Guédon
2023-02-06 16:54:51 +01:00
committed by sosthene-nitrokey
parent 923a731d31
commit 28ac8cd592
2 changed files with 33 additions and 33 deletions
+7 -7
View File
@@ -85,7 +85,7 @@ impl ApduDispatch {
fn apdu_type<const S: usize>(apdu: &iso7816::Command<S>) -> RequestType {
info!("instruction: {:?} {}", apdu.instruction(), apdu.p1);
if apdu.instruction() == Instruction::Select && (apdu.p1 & 0x04) != 0 {
Aid::try_new(&apdu.data()).map_or(RequestType::NewCommand, RequestType::Select)
Aid::try_new(apdu.data()).map_or(RequestType::NewCommand, RequestType::Select)
} else if apdu.instruction() == Instruction::GetResponse {
RequestType::GetResponse
} else {
@@ -319,7 +319,7 @@ impl ApduDispatch {
.expect("Failed to add the status bytes");
(
RawApduBuffer::None,
interchanges::Data::from_slice(&res.as_slice()).unwrap(),
interchanges::Data::from_slice(res.as_slice()).unwrap(),
)
}
}
@@ -346,9 +346,9 @@ impl ApduDispatch {
}
#[inline(never)]
fn handle_app_select<'a>(
fn handle_app_select(
&mut self,
apps: &mut [&'a mut dyn App<CommandSize, ResponseSize>],
apps: &mut [&mut dyn App<CommandSize, ResponseSize>],
aid: Aid,
) {
// three cases:
@@ -391,7 +391,7 @@ impl ApduDispatch {
}
#[inline(never)]
fn handle_app_command<'a>(&mut self, apps: &mut [&'a mut dyn App<CommandSize, ResponseSize>]) {
fn handle_app_command(&mut self, apps: &mut [&mut dyn App<CommandSize, ResponseSize>]) {
// if there is a selected app, send it the command
let mut response = response::Data::new();
if let Some(app) = Self::find_app(self.current_aid.as_ref(), apps) {
@@ -409,9 +409,9 @@ impl ApduDispatch {
};
}
pub fn poll<'a>(
pub fn poll(
&mut self,
apps: &mut [&'a mut dyn App<CommandSize, ResponseSize>],
apps: &mut [&mut dyn App<CommandSize, ResponseSize>],
) -> Option<Interface> {
// Only take on one transaction at a time.
let request_type = self.check_for_request();
+26 -26
View File
@@ -17,7 +17,7 @@ generate_macros!();
pub struct StdoutFlusher {}
impl delog::Flusher for StdoutFlusher {
fn flush(&self, logs: &str) {
print!("{}", logs);
print!("{logs}");
}
}
@@ -33,8 +33,8 @@ enum TestInstruction {
}
fn dump_hex(data: &[u8]) {
for i in 0..data.len() {
print!("{:02X} ", data[i]);
for b in data {
print!("{b:02X} ");
}
println!();
}
@@ -50,7 +50,7 @@ impl iso7816::App for TestApp1 {
// This app echos to Ins code 0x10
impl App<{ apdu_dispatch::command::SIZE }, { apdu_dispatch::response::SIZE }> for TestApp1 {
fn select(&mut self, _apdu: &Command, _reply: &mut response::Data) -> AppResult {
Ok(Default::default())
Ok(())
}
fn deselect(&mut self) {}
@@ -120,7 +120,7 @@ impl iso7816::App for TestApp2 {
// This app echos to Ins code 0x20
impl App<{ apdu_dispatch::command::SIZE }, { apdu_dispatch::response::SIZE }> for TestApp2 {
fn select(&mut self, _apdu: &Command, _reply: &mut response::Data) -> AppResult {
Ok(Default::default())
Ok(())
}
fn deselect(&mut self) {}
@@ -185,7 +185,7 @@ impl App<{ apdu_dispatch::command::SIZE }, { apdu_dispatch::response::SIZE }> fo
}
fn run_apdus(apdu_response_pairs: &[&[u8]]) {
assert!(apdu_response_pairs.len() > 0);
assert!(!apdu_response_pairs.is_empty());
assert!((apdu_response_pairs.len() & 1) == 0);
Delogger::init_default(delog::LevelFilter::Info, &STDOUT_FLUSHER).ok();
@@ -219,10 +219,10 @@ fn run_apdus(apdu_response_pairs: &[&[u8]]) {
// let expected_response = Response::Data::from_slice(&raw_res);
print!("<< ");
dump_hex(&raw_req);
dump_hex(raw_req);
contact_requester
.request(&interchanges::Data::from_slice(&raw_req).unwrap())
.request(&interchanges::Data::from_slice(raw_req).unwrap())
.expect("could not deposit command");
apdu_dispatch.poll(&mut [&mut app0, &mut app1, &mut app2, &mut app3, &mut app4]);
@@ -235,7 +235,7 @@ fn run_apdus(apdu_response_pairs: &[&[u8]]) {
if raw_expected_res != response.as_slice() {
print!("expected: ");
dump_hex(&raw_expected_res);
dump_hex(raw_expected_res);
print!("got: ");
dump_hex(&response);
panic!("Expected responses do not match");
@@ -788,7 +788,7 @@ fn test_chained_fibonacci_response() {
chunk.push(0x00).unwrap();
}
*start += size;
return chunk;
chunk
}
let mut start = 0;
@@ -820,53 +820,53 @@ fn test_chained_fibonacci_response() {
/* 1 */ 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
00
"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start, 256).as_slice(),
apdu_res_chunk(&expected, &mut start, 256).as_slice(),
// chaining bit, command to get long fibonacci back
&hex!("10300000 05 0102030405"),
&hex!("9000 "),
&hex!("00300000 05 0102030405 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
&hex!("00C00000 00"),
&apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
apdu_res_chunk(&expected, &mut start2, 256).as_slice(),
]
)