@@ -4,11 +4,12 @@ use std::sync::Arc;
44use std:: time:: Duration ;
55
66use libwebauthn:: pin:: PinRequestReason ;
7+ use libwebauthn:: transport:: cable:: channel:: CableUxUpdate ;
78use libwebauthn:: transport:: cable:: known_devices:: {
89 CableKnownDevice , ClientPayloadHint , EphemeralDeviceInfoStore ,
910} ;
1011use libwebauthn:: transport:: cable:: qr_code_device:: { CableQrCodeDevice , QrCodeOperationHint } ;
11- use libwebauthn:: UxUpdate ;
12+ use libwebauthn:: UvUpdate ;
1213use qrcode:: render:: unicode;
1314use qrcode:: QrCode ;
1415use rand:: { thread_rng, Rng } ;
@@ -36,42 +37,44 @@ fn setup_logging() {
3637 . init ( ) ;
3738}
3839
39- async fn handle_updates ( mut state_recv : Receiver < UxUpdate > ) {
40+ async fn handle_updates ( mut state_recv : Receiver < CableUxUpdate > ) {
4041 while let Some ( update) = state_recv. recv ( ) . await {
4142 match update {
42- UxUpdate :: PresenceRequired => println ! ( "Please touch your device!" ) ,
43- UxUpdate :: UvRetry { attempts_left } => {
44- print ! ( "UV failed." ) ;
45- if let Some ( attempts_left) = attempts_left {
46- print ! ( " You have {attempts_left} attempts left." ) ;
43+ CableUxUpdate :: UvUpdate ( uv_update) => match uv_update {
44+ UvUpdate :: PresenceRequired => println ! ( "Please touch your device!" ) ,
45+ UvUpdate :: UvRetry { attempts_left } => {
46+ print ! ( "UV failed." ) ;
47+ if let Some ( attempts_left) = attempts_left {
48+ print ! ( " You have {attempts_left} attempts left." ) ;
49+ }
4750 }
48- }
49- UxUpdate :: PinRequired ( update) => {
50- let mut attempts_str = String :: new ( ) ;
51- if let Some ( attempts) = update. attempts_left {
52- attempts_str = format ! ( ". You have {attempts} attempts left!" ) ;
53- } ;
54-
55- match update. reason {
56- PinRequestReason :: RelyingPartyRequest => println ! ( "RP required a PIN." ) ,
57- PinRequestReason :: AuthenticatorPolicy => {
58- println ! ( "Your device requires a PIN." )
51+ UvUpdate :: PinRequired ( update) => {
52+ let mut attempts_str = String :: new ( ) ;
53+ if let Some ( attempts) = update. attempts_left {
54+ attempts_str = format ! ( ". You have {attempts} attempts left!" ) ;
55+ } ;
56+
57+ match update. reason {
58+ PinRequestReason :: RelyingPartyRequest => println ! ( "RP required a PIN." ) ,
59+ PinRequestReason :: AuthenticatorPolicy => {
60+ println ! ( "Your device requires a PIN." )
61+ }
62+ PinRequestReason :: FallbackFromUV => {
63+ println ! ( "UV failed too often and is blocked. Falling back to PIN." )
64+ }
5965 }
60- PinRequestReason :: FallbackFromUV => {
61- println ! ( "UV failed too often and is blocked. Falling back to PIN." )
66+ print ! ( "PIN: Please enter the PIN for your authenticator{attempts_str}: " ) ;
67+ io:: stdout ( ) . flush ( ) . unwrap ( ) ;
68+ let pin_raw: String = read ! ( "{}\n " ) ;
69+
70+ if pin_raw. is_empty ( ) {
71+ println ! ( "PIN: No PIN provided, cancelling operation." ) ;
72+ update. cancel ( ) ;
73+ } else {
74+ let _ = update. send_pin ( & pin_raw) ;
6275 }
6376 }
64- print ! ( "PIN: Please enter the PIN for your authenticator{attempts_str}: " ) ;
65- io:: stdout ( ) . flush ( ) . unwrap ( ) ;
66- let pin_raw: String = read ! ( "{}\n " ) ;
67-
68- if pin_raw. is_empty ( ) {
69- println ! ( "PIN: No PIN provided, cancelling operation." ) ;
70- update. cancel ( ) ;
71- } else {
72- let _ = update. send_pin ( & pin_raw) ;
73- }
74- }
77+ } ,
7578 }
7679 }
7780}
0 commit comments