1111use crate :: command:: SIZE as CommandSize ;
1212use crate :: response:: SIZE as ResponseSize ;
1313use crate :: App ;
14- use crate :: { interchanges, response, Command } ;
14+ use crate :: {
15+ interchanges:: { self , Responder } ,
16+ response, Command ,
17+ } ;
1518use core:: convert:: TryInto ;
1619
1720use iso7816:: { command:: FromSliceError , Aid , Instruction , Result , Status } ;
@@ -36,8 +39,6 @@ pub enum RequestType {
3639 None ,
3740}
3841
39- use interchange:: Responder ;
40-
4142#[ derive( PartialEq ) ]
4243enum RawApduBuffer {
4344 None ,
@@ -71,19 +72,19 @@ impl ApduBuffer {
7172 }
7273}
7374
74- pub struct ApduDispatch {
75+ pub struct ApduDispatch < ' pipe > {
7576 // or currently_selected_aid, or...
7677 current_aid : Option < Aid > ,
77- contact : Responder < interchanges :: Contact > ,
78- contactless : Responder < interchanges :: Contactless > ,
78+ contact : Responder < ' pipe > ,
79+ contactless : Responder < ' pipe > ,
7980 current_interface : Interface ,
8081
8182 buffer : ApduBuffer ,
8283 response_len_expected : usize ,
8384 was_request_chained : bool ,
8485}
8586
86- impl ApduDispatch {
87+ impl < ' pipe > ApduDispatch < ' pipe > {
8788 fn apdu_type < const S : usize > ( apdu : & iso7816:: Command < S > ) -> RequestType {
8889 info ! ( "instruction: {:?} {}" , apdu. instruction( ) , apdu. p1) ;
8990 if apdu. instruction ( ) == Instruction :: Select && ( apdu. p1 & 0x04 ) != 0 {
@@ -101,10 +102,7 @@ impl ApduDispatch {
101102 }
102103 }
103104
104- pub fn new (
105- contact : Responder < interchanges:: Contact > ,
106- contactless : Responder < interchanges:: Contactless > ,
107- ) -> ApduDispatch {
105+ pub fn new ( contact : Responder < ' pipe > , contactless : Responder < ' pipe > ) -> Self {
108106 ApduDispatch {
109107 current_aid : None ,
110108 contact,
@@ -185,12 +183,12 @@ impl ApduDispatch {
185183 // acknowledge
186184 Interface :: Contact => {
187185 self . contact
188- . respond ( & Status :: Success . try_into ( ) . unwrap ( ) )
186+ . respond ( Status :: Success . try_into ( ) . unwrap ( ) )
189187 . expect ( "Could not respond" ) ;
190188 }
191189 Interface :: Contactless => {
192190 self . contactless
193- . respond ( & Status :: Success . try_into ( ) . unwrap ( ) )
191+ . respond ( Status :: Success . try_into ( ) . unwrap ( ) )
194192 . expect ( "Could not respond" ) ;
195193 }
196194 }
@@ -258,12 +256,11 @@ impl ApduDispatch {
258256 match interface {
259257 Interface :: Contactless => self
260258 . contactless
261- . respond ( & response. into ( ) )
262- . expect ( "cant respond" ) ,
263- Interface :: Contact => self
264- . contact
265- . respond ( & response. into ( ) )
259+ . respond ( response. into ( ) )
266260 . expect ( "cant respond" ) ,
261+ Interface :: Contact => {
262+ self . contact . respond ( response. into ( ) ) . expect ( "cant respond" )
263+ }
267264 }
268265 RequestType :: None
269266 }
@@ -275,7 +272,7 @@ impl ApduDispatch {
275272
276273 #[ inline( never) ]
277274 fn reply_error ( & mut self , status : Status ) {
278- self . respond ( & status. into ( ) ) ;
275+ self . respond ( status. into ( ) ) ;
279276 self . buffer . raw = RawApduBuffer :: None ;
280277 }
281278
@@ -333,7 +330,7 @@ impl ApduDispatch {
333330 }
334331 } ;
335332 self . buffer . raw = new_state;
336- self . respond ( & response) ;
333+ self . respond ( response) ;
337334 }
338335
339336 #[ inline( never) ]
@@ -463,7 +460,7 @@ impl ApduDispatch {
463460 }
464461
465462 #[ inline( never) ]
466- fn respond ( & mut self , message : & interchanges:: Data ) {
463+ fn respond ( & mut self , message : interchanges:: Data ) {
467464 debug ! ( "<< {}" , hex_str!( message. as_slice( ) , sep: "" ) ) ;
468465 match self . current_interface {
469466 Interface :: Contactless => self . contactless . respond ( message) . expect ( "cant respond" ) ,
0 commit comments