@@ -11,10 +11,7 @@ use libwebauthn::transport::cable::qr_code_device::{CableQrCodeDevice, QrCodeOpe
1111use libwebauthn:: transport:: Device ;
1212use libwebauthn:: webauthn:: { Error as WebAuthnError , WebAuthn } ;
1313
14- use crate :: {
15- dbus:: CredentialRequest ,
16- tokio_runtime,
17- } ;
14+ use crate :: { dbus:: CredentialRequest , tokio_runtime} ;
1815
1916use super :: AuthenticatorResponse ;
2017
@@ -23,16 +20,14 @@ pub(crate) trait HybridHandler {
2320 fn start ( & self , request : & CredentialRequest ) -> Self :: Stream ;
2421}
2522
26-
2723#[ derive( Debug ) ]
2824pub struct InternalHybridHandler { }
2925impl InternalHybridHandler {
3026 pub fn new ( ) -> Self {
31- Self { }
27+ Self { }
3228 }
3329}
3430
35-
3631impl HybridHandler for InternalHybridHandler {
3732 type Stream = InternalHybridStream ;
3833
@@ -41,8 +36,12 @@ impl HybridHandler for InternalHybridHandler {
4136 let ( tx, rx) = async_std:: channel:: unbounded ( ) ;
4237 async_std:: task:: spawn ( async move {
4338 let hint = match request {
44- CredentialRequest :: CreatePublicKeyCredentialRequest ( _) => QrCodeOperationHint :: MakeCredential ,
45- CredentialRequest :: GetPublicKeyCredentialRequest ( _) => QrCodeOperationHint :: GetAssertionRequest ,
39+ CredentialRequest :: CreatePublicKeyCredentialRequest ( _) => {
40+ QrCodeOperationHint :: MakeCredential
41+ }
42+ CredentialRequest :: GetPublicKeyCredentialRequest ( _) => {
43+ QrCodeOperationHint :: GetAssertionRequest
44+ }
4645 } ;
4746 let mut device = CableQrCodeDevice :: new_transient ( hint) ;
4847 let qr_code = device. qr_code . to_string ( ) ;
@@ -55,10 +54,7 @@ impl HybridHandler for InternalHybridHandler {
5554 let response: AuthenticatorResponse = loop {
5655 match & request {
5756 CredentialRequest :: CreatePublicKeyCredentialRequest ( make_request) => {
58- match channel
59- . webauthn_make_credential ( & make_request)
60- . await
61- {
57+ match channel. webauthn_make_credential ( & make_request) . await {
6258 Ok ( response) => break Ok ( response. into ( ) ) ,
6359 Err ( WebAuthnError :: Ctap ( ctap_error) ) => {
6460 if ctap_error. is_retryable_user_error ( ) {
@@ -69,13 +65,9 @@ impl HybridHandler for InternalHybridHandler {
6965 }
7066 Err ( err) => break Err ( err) ,
7167 } ;
72-
7368 }
7469 CredentialRequest :: GetPublicKeyCredentialRequest ( get_request) => {
75- match channel
76- . webauthn_get_assertion ( & get_request)
77- . await
78- {
70+ match channel. webauthn_get_assertion ( & get_request) . await {
7971 Ok ( response) => break Ok ( response. into ( ) ) ,
8072 Err ( WebAuthnError :: Ctap ( ctap_error) ) => {
8173 if ctap_error. is_retryable_user_error ( ) {
@@ -86,29 +78,30 @@ impl HybridHandler for InternalHybridHandler {
8678 }
8779 Err ( err) => break Err ( err) ,
8880 } ;
89-
9081 }
9182 }
9283 }
9384 . unwrap ( ) ;
9485 if let Err ( err) = tx. send ( HybridStateInternal :: Completed ( response) ) . await {
9586 tracing:: error!( "Failed to send caBLE update: {:?}" , err)
9687 }
97-
9888 } ) ;
9989 } ) ;
10090 InternalHybridStream { rx }
10191 }
10292}
10393
10494pub struct InternalHybridStream {
105- rx : Receiver < HybridStateInternal >
95+ rx : Receiver < HybridStateInternal > ,
10696}
10797
10898impl Stream for InternalHybridStream {
10999 type Item = HybridStateInternal ;
110100
111- fn poll_next ( self : std:: pin:: Pin < & mut Self > , cx : & mut std:: task:: Context < ' _ > ) -> Poll < Option < Self :: Item > > {
101+ fn poll_next (
102+ self : std:: pin:: Pin < & mut Self > ,
103+ cx : & mut std:: task:: Context < ' _ > ,
104+ ) -> Poll < Option < Self :: Item > > {
112105 match self . rx . recv ( ) . poll ( cx) {
113106 Poll :: Pending => Poll :: Pending ,
114107 Poll :: Ready ( Ok ( state) ) => Poll :: Ready ( Some ( state) ) ,
@@ -126,15 +119,15 @@ impl DummyHybridHandler {
126119 #[ cfg( test) ]
127120 pub fn new ( states : Vec < HybridStateInternal > ) -> Self {
128121 Self {
129- stream : DummyHybridStateStream { states }
122+ stream : DummyHybridStateStream { states } ,
130123 }
131124 }
132125}
133126
134127impl Default for DummyHybridHandler {
135128 fn default ( ) -> Self {
136129 Self {
137- stream : DummyHybridStateStream :: default ( )
130+ stream : DummyHybridStateStream :: default ( ) ,
138131 }
139132 }
140133}
@@ -254,11 +247,10 @@ impl From<HybridStateInternal> for HybridState {
254247 fn from ( value : HybridStateInternal ) -> Self {
255248 match value {
256249 HybridStateInternal :: Init ( qr_code) => HybridState :: Init ( qr_code) ,
257- HybridStateInternal :: Waiting => HybridState :: Waiting ,
258- HybridStateInternal :: Connecting => HybridState :: Connecting ,
259- HybridStateInternal :: Completed ( _) => HybridState :: Completed ,
250+ HybridStateInternal :: Waiting => HybridState :: Waiting ,
251+ HybridStateInternal :: Connecting => HybridState :: Connecting ,
252+ HybridStateInternal :: Completed ( _) => HybridState :: Completed ,
260253 HybridStateInternal :: UserCancelled => HybridState :: UserCancelled ,
261-
262254 }
263255 }
264256}
0 commit comments