diff --git a/src/dispatch.rs b/src/dispatch.rs index 568d013..6e2c621 100644 --- a/src/dispatch.rs +++ b/src/dispatch.rs @@ -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()); @@ -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()); } } }