Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cancellation requests #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}