@@ -195,14 +195,10 @@ impl GetAssertion {
195195 // Handle extensions whose outputs are not encoded in the authenticator data.
196196 // 1. appId
197197 if let Some ( app_id) = & self . extensions . app_id {
198- result. extensions . app_id = result
199- . assertions
200- . first ( )
201- . map ( |assertion| {
202- assertion. auth_data . rp_id_hash
203- == RelyingPartyWrapper :: from ( app_id. as_str ( ) ) . hash ( )
204- } )
205- . or ( Some ( false ) ) ;
198+ result. extensions . app_id = Some (
199+ result. assertion . auth_data . rp_id_hash
200+ == RelyingPartyWrapper :: from ( app_id. as_str ( ) ) . hash ( ) ,
201+ ) ;
206202 }
207203 }
208204}
@@ -307,7 +303,7 @@ impl Serialize for GetAssertion {
307303}
308304
309305impl RequestCtap1 for GetAssertion {
310- type Output = GetAssertionResult ;
306+ type Output = Vec < GetAssertionResult > ;
311307 type AdditionalInfo = PublicKeyCredentialDescriptor ;
312308
313309 fn ctap1_format ( & self ) -> Result < ( Vec < u8 > , Self :: AdditionalInfo ) , HIDError > {
@@ -358,24 +354,27 @@ impl RequestCtap1 for GetAssertion {
358354 return Err ( Retryable :: Error ( HIDError :: ApduStatus ( err) ) ) ;
359355 }
360356
361- let mut output = GetAssertionResult :: from_ctap1 ( input, & self . rp . hash ( ) , add_info)
357+ let mut result = GetAssertionResult :: from_ctap1 ( input, & self . rp . hash ( ) , add_info)
362358 . map_err ( |e| Retryable :: Error ( HIDError :: Command ( e) ) ) ?;
363- self . finalize_result ( & mut output) ;
364- Ok ( output)
359+ self . finalize_result ( & mut result) ;
360+ // Although there's only one result, we return a vector for consistency with CTAP2.
361+ Ok ( vec ! [ result] )
365362 }
366363
367364 fn send_to_virtual_device < Dev : VirtualFidoDevice > (
368365 & self ,
369366 dev : & mut Dev ,
370367 ) -> Result < Self :: Output , HIDError > {
371- let mut output = dev. get_assertion ( self ) ?;
372- self . finalize_result ( & mut output) ;
373- Ok ( output)
368+ let mut results = dev. get_assertion ( self ) ?;
369+ for result in results. iter_mut ( ) {
370+ self . finalize_result ( result) ;
371+ }
372+ Ok ( results)
374373 }
375374}
376375
377376impl RequestCtap2 for GetAssertion {
378- type Output = GetAssertionResult ;
377+ type Output = Vec < GetAssertionResult > ;
379378
380379 fn command ( & self ) -> Command {
381380 Command :: GetAssertion
@@ -411,22 +410,27 @@ impl RequestCtap2 for GetAssertion {
411410 let assertion: GetAssertionResponse =
412411 from_slice ( & input[ 1 ..] ) . map_err ( CommandError :: Deserializing ) ?;
413412 let number_of_credentials = assertion. number_of_credentials . unwrap_or ( 1 ) ;
414- let mut assertions = Vec :: with_capacity ( number_of_credentials) ;
415- assertions. push ( assertion. into ( ) ) ;
413+
414+ let mut results = Vec :: with_capacity ( number_of_credentials) ;
415+ results. push ( GetAssertionResult {
416+ assertion : assertion. into ( ) ,
417+ extensions : Default :: default ( ) ,
418+ } ) ;
416419
417420 let msg = GetNextAssertion ;
418421 // We already have one, so skipping 0
419422 for _ in 1 ..number_of_credentials {
420- let new_cred = dev. send_cbor ( & msg) ?;
421- assertions. push ( new_cred. into ( ) ) ;
423+ let assertion = dev. send_cbor ( & msg) ?;
424+ results. push ( GetAssertionResult {
425+ assertion : assertion. into ( ) ,
426+ extensions : Default :: default ( ) ,
427+ } ) ;
422428 }
423429
424- let mut output = GetAssertionResult {
425- assertions,
426- extensions : Default :: default ( ) ,
427- } ;
428- self . finalize_result ( & mut output) ;
429- Ok ( output)
430+ for result in results. iter_mut ( ) {
431+ self . finalize_result ( result) ;
432+ }
433+ Ok ( results)
430434 } else {
431435 let data: Value = from_slice ( & input[ 1 ..] ) . map_err ( CommandError :: Deserializing ) ?;
432436 Err ( CommandError :: StatusCode ( status, Some ( data) ) . into ( ) )
@@ -437,9 +441,11 @@ impl RequestCtap2 for GetAssertion {
437441 & self ,
438442 dev : & mut Dev ,
439443 ) -> Result < Self :: Output , HIDError > {
440- let mut output = dev. get_assertion ( self ) ?;
441- self . finalize_result ( & mut output) ;
442- Ok ( output)
444+ let mut results = dev. get_assertion ( self ) ?;
445+ for result in results. iter_mut ( ) {
446+ self . finalize_result ( result) ;
447+ }
448+ Ok ( results)
443449 }
444450}
445451
@@ -465,7 +471,7 @@ impl From<GetAssertionResponse> for Assertion {
465471
466472#[ derive( Debug , PartialEq , Eq ) ]
467473pub struct GetAssertionResult {
468- pub assertions : Vec < Assertion > ,
474+ pub assertion : Assertion ,
469475 pub extensions : AuthenticationExtensionsClientOutputs ,
470476}
471477
@@ -501,23 +507,10 @@ impl GetAssertionResult {
501507 } ;
502508
503509 Ok ( GetAssertionResult {
504- assertions : vec ! [ assertion] ,
510+ assertion,
505511 extensions : Default :: default ( ) ,
506512 } )
507513 }
508-
509- pub fn u2f_sign_data ( & self ) -> Vec < u8 > {
510- if let Some ( first) = self . assertions . first ( ) {
511- let mut res = Vec :: new ( ) ;
512- res. push ( first. auth_data . flags . bits ( ) ) ;
513- res. extend ( first. auth_data . counter . to_be_bytes ( ) ) ;
514- res. extend ( & first. signature ) ;
515- res
516- // first.signature.clone()
517- } else {
518- Vec :: new ( )
519- }
520- }
521514}
522515
523516pub struct GetAssertionResponse {
@@ -791,10 +784,10 @@ pub mod test {
791784 auth_data : expected_auth_data,
792785 } ;
793786
794- let expected = GetAssertionResult {
795- assertions : vec ! [ expected_assertion] ,
787+ let expected = vec ! [ GetAssertionResult {
788+ assertion : expected_assertion,
796789 extensions: Default :: default ( ) ,
797- } ;
790+ } ] ;
798791 let response = device. send_cbor ( & assertion) . unwrap ( ) ;
799792 assert_eq ! ( response, expected) ;
800793 }
@@ -926,10 +919,10 @@ pub mod test {
926919 auth_data : expected_auth_data,
927920 } ;
928921
929- let expected = GetAssertionResult {
930- assertions : vec ! [ expected_assertion] ,
922+ let expected = vec ! [ GetAssertionResult {
923+ assertion : expected_assertion,
931924 extensions: Default :: default ( ) ,
932- } ;
925+ } ] ;
933926 assert_eq ! ( response, expected) ;
934927 }
935928
@@ -1070,10 +1063,10 @@ pub mod test {
10701063 auth_data : expected_auth_data,
10711064 } ;
10721065
1073- let expected = GetAssertionResult {
1074- assertions : vec ! [ expected_assertion] ,
1066+ let expected = vec ! [ GetAssertionResult {
1067+ assertion : expected_assertion,
10751068 extensions: Default :: default ( ) ,
1076- } ;
1069+ } ] ;
10771070 assert_eq ! ( response, expected) ;
10781071 }
10791072
@@ -1338,7 +1331,7 @@ pub mod test {
13381331 let resp = GetAssertionResult :: from_ctap1 ( & sample, & rp_hash, & add_info)
13391332 . expect ( "could not handle response" ) ;
13401333 assert_eq ! (
1341- resp. assertions [ 0 ] . auth_data. flags,
1334+ resp. assertion . auth_data. flags,
13421335 AuthenticatorDataFlags :: USER_PRESENT | AuthenticatorDataFlags :: RESERVED_1
13431336 ) ;
13441337 }
0 commit comments