Skip to content

Commit d1aa3fb

Browse files
Generalise Channel::UxUpdate, allowing transport-specific types
1 parent ad4c843 commit d1aa3fb

28 files changed

+159
-130
lines changed

libwebauthn/examples/authenticator_config_hid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use libwebauthn::proto::ctap2::{Ctap2, Ctap2GetInfoResponse};
88
use libwebauthn::transport::hid::list_devices;
99
use libwebauthn::transport::Device;
1010
use libwebauthn::webauthn::Error as WebAuthnError;
11-
use libwebauthn::UxUpdate;
11+
use libwebauthn::UvUpdate;
1212
use std::io::{self, Write};
1313
use text_io::read;
1414
use tokio::sync::mpsc::Receiver;
@@ -23,17 +23,17 @@ fn setup_logging() {
2323
.init();
2424
}
2525

26-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
26+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
2727
while let Some(update) = state_recv.recv().await {
2828
match update {
29-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
30-
UxUpdate::UvRetry { attempts_left } => {
29+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
30+
UvUpdate::UvRetry { attempts_left } => {
3131
print!("UV failed.");
3232
if let Some(attempts_left) = attempts_left {
3333
print!(" You have {attempts_left} attempts left.");
3434
}
3535
}
36-
UxUpdate::PinRequired(update) => {
36+
UvUpdate::PinRequired(update) => {
3737
let mut attempts_str = String::new();
3838
if let Some(attempts) = update.attempts_left {
3939
attempts_str = format!(". You have {attempts} attempts left!");

libwebauthn/examples/bio_enrollment_hid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use libwebauthn::UxUpdate;
1+
use libwebauthn::UvUpdate;
22
use std::error::Error;
33
use std::fmt::Display;
44
use std::io::{self, Write};
@@ -23,17 +23,17 @@ fn setup_logging() {
2323
.init();
2424
}
2525

26-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
26+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
2727
while let Some(update) = state_recv.recv().await {
2828
match update {
29-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
30-
UxUpdate::UvRetry { attempts_left } => {
29+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
30+
UvUpdate::UvRetry { attempts_left } => {
3131
print!("UV failed.");
3232
if let Some(attempts_left) = attempts_left {
3333
print!(" You have {attempts_left} attempts left.");
3434
}
3535
}
36-
UxUpdate::PinRequired(update) => {
36+
UvUpdate::PinRequired(update) => {
3737
let mut attempts_str = String::new();
3838
if let Some(attempts) = update.attempts_left {
3939
attempts_str = format!(". You have {attempts} attempts left!");

libwebauthn/examples/change_pin_hid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33

44
use libwebauthn::{
55
pin::{PinManagement, PinRequestReason},
6-
UxUpdate,
6+
UvUpdate,
77
};
88
use tokio::sync::mpsc::Receiver;
99
use tracing_subscriber::{self, EnvFilter};
@@ -23,17 +23,17 @@ fn setup_logging() {
2323
.init();
2424
}
2525

26-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
26+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
2727
while let Some(update) = state_recv.recv().await {
2828
match update {
29-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
30-
UxUpdate::UvRetry { attempts_left } => {
29+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
30+
UvUpdate::UvRetry { attempts_left } => {
3131
print!("UV failed.");
3232
if let Some(attempts_left) = attempts_left {
3333
print!(" You have {attempts_left} attempts left.");
3434
}
3535
}
36-
UxUpdate::PinRequired(update) => {
36+
UvUpdate::PinRequired(update) => {
3737
let mut attempts_str = String::new();
3838
if let Some(attempts) = update.attempts_left {
3939
attempts_str = format!(". You have {attempts} attempts left!");

libwebauthn/examples/cred_management.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use libwebauthn::proto::CtapError;
77
use libwebauthn::transport::hid::list_devices;
88
use libwebauthn::transport::Device;
99
use libwebauthn::webauthn::Error as WebAuthnError;
10-
use libwebauthn::UxUpdate;
10+
use libwebauthn::UvUpdate;
1111
use std::fmt::Display;
1212
use std::io::{self, Write};
1313
use std::time::Duration;
@@ -24,17 +24,17 @@ fn setup_logging() {
2424
.init();
2525
}
2626

27-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
27+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
2828
while let Some(update) = state_recv.recv().await {
2929
match update {
30-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
31-
UxUpdate::UvRetry { attempts_left } => {
30+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
31+
UvUpdate::UvRetry { attempts_left } => {
3232
print!("UV failed.");
3333
if let Some(attempts_left) = attempts_left {
3434
print!(" You have {attempts_left} attempts left.");
3535
}
3636
}
37-
UxUpdate::PinRequired(update) => {
37+
UvUpdate::PinRequired(update) => {
3838
let mut attempts_str = String::new();
3939
if let Some(attempts) = update.attempts_left {
4040
attempts_str = format!(". You have {attempts} attempts left!");

libwebauthn/examples/prf_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::{self, Write};
55
use std::time::Duration;
66

77
use libwebauthn::transport::hid::channel::HidChannel;
8-
use libwebauthn::UxUpdate;
8+
use libwebauthn::UvUpdate;
99
use rand::{thread_rng, Rng};
1010
use serde_bytes::ByteBuf;
1111
use text_io::read;
@@ -31,17 +31,17 @@ fn setup_logging() {
3131
.init();
3232
}
3333

34-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
34+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
3535
while let Some(update) = state_recv.recv().await {
3636
match update {
37-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
38-
UxUpdate::UvRetry { attempts_left } => {
37+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
38+
UvUpdate::UvRetry { attempts_left } => {
3939
print!("UV failed.");
4040
if let Some(attempts_left) = attempts_left {
4141
print!(" You have {attempts_left} attempts left.");
4242
}
4343
}
44-
UxUpdate::PinRequired(update) => {
44+
UvUpdate::PinRequired(update) => {
4545
let mut attempts_str = String::new();
4646
if let Some(attempts) = update.attempts_left {
4747
attempts_str = format!(". You have {attempts} attempts left!");

libwebauthn/examples/u2f_ble.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::error::Error;
22
use std::time::Duration;
33

4-
use libwebauthn::UxUpdate;
4+
use libwebauthn::UvUpdate;
55
use tokio::sync::mpsc::Receiver;
66
use tracing_subscriber::{self, EnvFilter};
77

@@ -19,10 +19,10 @@ fn setup_logging() {
1919
.init();
2020
}
2121

22-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
22+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
2323
while let Some(update) = state_recv.recv().await {
2424
match update {
25-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
25+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
2626
_ => { /* U2F doesn't use other state updates */ }
2727
}
2828
}

libwebauthn/examples/u2f_hid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::error::Error;
22
use std::time::Duration;
33

4-
use libwebauthn::UxUpdate;
4+
use libwebauthn::UvUpdate;
55
use tokio::sync::mpsc::Receiver;
66
use tracing_subscriber::{self, EnvFilter};
77

@@ -20,10 +20,10 @@ fn setup_logging() {
2020
.init();
2121
}
2222

23-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
23+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
2424
while let Some(update) = state_recv.recv().await {
2525
match update {
26-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
26+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
2727
_ => { /* U2F doesn't use other state updates */ }
2828
}
2929
}

libwebauthn/examples/webauthn_cable.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use std::sync::Arc;
44
use std::time::Duration;
55

66
use libwebauthn::pin::PinRequestReason;
7+
use libwebauthn::transport::cable::channel::CableUxUpdate;
78
use libwebauthn::transport::cable::known_devices::{
89
CableKnownDevice, ClientPayloadHint, EphemeralDeviceInfoStore,
910
};
1011
use libwebauthn::transport::cable::qr_code_device::{CableQrCodeDevice, QrCodeOperationHint};
11-
use libwebauthn::UxUpdate;
12+
use libwebauthn::UvUpdate;
1213
use qrcode::render::unicode;
1314
use qrcode::QrCode;
1415
use 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
}

libwebauthn/examples/webauthn_extensions_hid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::error::Error;
33
use std::io::{self, Write};
44
use std::time::Duration;
55

6-
use libwebauthn::UxUpdate;
6+
use libwebauthn::UvUpdate;
77
use rand::{thread_rng, Rng};
88
use text_io::read;
99
use tokio::sync::mpsc::Receiver;
@@ -33,17 +33,17 @@ fn setup_logging() {
3333
.init();
3434
}
3535

36-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
36+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
3737
while let Some(update) = state_recv.recv().await {
3838
match update {
39-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
40-
UxUpdate::UvRetry { attempts_left } => {
39+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
40+
UvUpdate::UvRetry { attempts_left } => {
4141
print!("UV failed.");
4242
if let Some(attempts_left) = attempts_left {
4343
print!(" You have {attempts_left} attempts left.");
4444
}
4545
}
46-
UxUpdate::PinRequired(update) => {
46+
UvUpdate::PinRequired(update) => {
4747
let mut attempts_str = String::new();
4848
if let Some(attempts) = update.attempts_left {
4949
attempts_str = format!(". You have {attempts} attempts left!");

libwebauthn/examples/webauthn_hid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::error::Error;
33
use std::io::{self, Write};
44
use std::time::Duration;
55

6-
use libwebauthn::UxUpdate;
6+
use libwebauthn::UvUpdate;
77
use rand::{thread_rng, Rng};
88
use text_io::read;
99
use tokio::sync::mpsc::Receiver;
@@ -30,17 +30,17 @@ fn setup_logging() {
3030
.init();
3131
}
3232

33-
async fn handle_updates(mut state_recv: Receiver<UxUpdate>) {
33+
async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
3434
while let Some(update) = state_recv.recv().await {
3535
match update {
36-
UxUpdate::PresenceRequired => println!("Please touch your device!"),
37-
UxUpdate::UvRetry { attempts_left } => {
36+
UvUpdate::PresenceRequired => println!("Please touch your device!"),
37+
UvUpdate::UvRetry { attempts_left } => {
3838
print!("UV failed.");
3939
if let Some(attempts_left) = attempts_left {
4040
print!(" You have {attempts_left} attempts left.");
4141
}
4242
}
43-
UxUpdate::PinRequired(update) => {
43+
UvUpdate::PinRequired(update) => {
4444
let mut attempts_str = String::new();
4545
if let Some(attempts) = update.attempts_left {
4646
attempts_str = format!(". You have {attempts} attempts left!");

0 commit comments

Comments
 (0)