Skip to content

Commit

Permalink
Handle cancellation requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jun 22, 2023
1 parent a6f0011 commit 2d509bd
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,7 @@ impl<'pipe> ApduDispatch<'pipe> {
apdu_type
}
} else {
match interface {
// acknowledge
Interface::Contact => {
self.contact
.respond(Status::Success.try_into().unwrap())
.expect("Could not respond");
}
Interface::Contactless => {
self.contactless
.respond(Status::Success.try_into().unwrap())
.expect("Could not respond");
}
}
self.respond(Status::Success.try_into().unwrap());

if !command.data().is_empty() {
info!("chaining {} bytes", command.data().len());
Expand Down Expand Up @@ -462,9 +450,16 @@ impl<'pipe> ApduDispatch<'pipe> {
#[inline(never)]
fn respond(&mut self, message: interchanges::Data) {
debug!("<< {}", hex_str!(message.as_slice(), sep:""));
match self.current_interface {
Interface::Contactless => self.contactless.respond(message).expect("cant respond"),
Interface::Contact => self.contact.respond(message).expect("cant respond"),
let (res, responder) = match self.current_interface {
Interface::Contactless => (self.contactless.respond(message), &mut self.contactless),
Interface::Contact => (self.contact.respond(message), &mut self.contact),
};
if res.is_ok() {
return;
}

if responder.acknowledge_cancel().is_err() {
panic!("Unexpected state: {:?}", responder.state());
}
}
}

0 comments on commit 2d509bd

Please sign in to comment.