@@ -179,19 +179,7 @@ impl<'pipe> ApduDispatch<'pipe> {
179179 apdu_type
180180 }
181181 } else {
182- match interface {
183- // acknowledge
184- Interface :: Contact => {
185- self . contact
186- . respond ( Status :: Success . try_into ( ) . unwrap ( ) )
187- . expect ( "Could not respond" ) ;
188- }
189- Interface :: Contactless => {
190- self . contactless
191- . respond ( Status :: Success . try_into ( ) . unwrap ( ) )
192- . expect ( "Could not respond" ) ;
193- }
194- }
182+ self . respond ( Status :: Success . try_into ( ) . unwrap ( ) ) ;
195183
196184 if !command. data ( ) . is_empty ( ) {
197185 info ! ( "chaining {} bytes" , command. data( ) . len( ) ) ;
@@ -462,9 +450,16 @@ impl<'pipe> ApduDispatch<'pipe> {
462450 #[ inline( never) ]
463451 fn respond ( & mut self , message : interchanges:: Data ) {
464452 debug ! ( "<< {}" , hex_str!( message. as_slice( ) , sep: "" ) ) ;
465- match self . current_interface {
466- Interface :: Contactless => self . contactless . respond ( message) . expect ( "cant respond" ) ,
467- Interface :: Contact => self . contact . respond ( message) . expect ( "cant respond" ) ,
453+ let ( res, responder) = match self . current_interface {
454+ Interface :: Contactless => ( self . contactless . respond ( message) , & mut self . contactless ) ,
455+ Interface :: Contact => ( self . contact . respond ( message) , & mut self . contact ) ,
456+ } ;
457+ if res. is_ok ( ) {
458+ return ;
459+ }
460+
461+ if responder. acknowledge_cancel ( ) . is_err ( ) {
462+ panic ! ( "Unexpected state: {:?}" , responder. state( ) ) ;
468463 }
469464 }
470465}
0 commit comments