Skip to content

Commit bea1b9c

Browse files
committed
Move get/set_device_info to HIDDevice and remove U2FDeviceInfo status updates
1 parent b444f32 commit bea1b9c

File tree

19 files changed

+111
-237
lines changed

19 files changed

+111
-237
lines changed

examples/ctap2.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,9 @@ fn main() {
8787
Ok(StatusUpdate::InteractiveManagement(..)) => {
8888
panic!("STATUS: This can't happen when doing non-interactive usage");
8989
}
90-
Ok(StatusUpdate::DeviceAvailable { dev_info }) => {
91-
println!("STATUS: device available: {dev_info}")
92-
}
93-
Ok(StatusUpdate::DeviceUnavailable { dev_info }) => {
94-
println!("STATUS: device unavailable: {dev_info}")
95-
}
96-
Ok(StatusUpdate::Success { dev_info }) => {
97-
println!("STATUS: success using device: {dev_info}");
98-
}
9990
Ok(StatusUpdate::SelectDeviceNotice) => {
10091
println!("STATUS: Please select a device by touching one of them.");
10192
}
102-
Ok(StatusUpdate::DeviceSelected(dev_info)) => {
103-
println!("STATUS: Continuing with device: {dev_info}");
104-
}
10593
Ok(StatusUpdate::PresenceRequired) => {
10694
println!("STATUS: waiting for user presence");
10795
}

examples/ctap2_discoverable_creds.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,9 @@ fn register_user(manager: &mut AuthenticatorService, username: &str, timeout_ms:
5050
Ok(StatusUpdate::InteractiveManagement(..)) => {
5151
panic!("STATUS: This can't happen when doing non-interactive usage");
5252
}
53-
Ok(StatusUpdate::DeviceAvailable { dev_info }) => {
54-
println!("STATUS: device available: {dev_info}")
55-
}
56-
Ok(StatusUpdate::DeviceUnavailable { dev_info }) => {
57-
println!("STATUS: device unavailable: {dev_info}")
58-
}
59-
Ok(StatusUpdate::Success { dev_info }) => {
60-
println!("STATUS: success using device: {dev_info}");
61-
}
6253
Ok(StatusUpdate::SelectDeviceNotice) => {
6354
println!("STATUS: Please select a device by touching one of them.");
6455
}
65-
Ok(StatusUpdate::DeviceSelected(dev_info)) => {
66-
println!("STATUS: Continuing with device: {dev_info}");
67-
}
6856
Ok(StatusUpdate::PresenceRequired) => {
6957
println!("STATUS: waiting for user presence");
7058
}
@@ -246,21 +234,9 @@ fn main() {
246234
Ok(StatusUpdate::InteractiveManagement(..)) => {
247235
panic!("STATUS: This can't happen when doing non-interactive usage");
248236
}
249-
Ok(StatusUpdate::DeviceAvailable { dev_info }) => {
250-
println!("STATUS: device available: {dev_info}")
251-
}
252-
Ok(StatusUpdate::DeviceUnavailable { dev_info }) => {
253-
println!("STATUS: device unavailable: {dev_info}")
254-
}
255-
Ok(StatusUpdate::Success { dev_info }) => {
256-
println!("STATUS: success using device: {dev_info}");
257-
}
258237
Ok(StatusUpdate::SelectDeviceNotice) => {
259238
println!("STATUS: Please select a device by touching one of them.");
260239
}
261-
Ok(StatusUpdate::DeviceSelected(dev_info)) => {
262-
println!("STATUS: Continuing with device: {dev_info}");
263-
}
264240
Ok(StatusUpdate::PresenceRequired) => {
265241
println!("STATUS: waiting for user presence");
266242
}

examples/interactive_management.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ fn print_usage(program: &str, opts: Options) {
2020
}
2121

2222
fn interactive_status_callback(status_rx: Receiver<StatusUpdate>) {
23-
let mut num_of_devices = 0;
2423
loop {
2524
match status_rx.recv() {
26-
Ok(StatusUpdate::InteractiveManagement((tx, dev_info, auth_info))) => {
27-
debug!(
28-
"STATUS: interactive management: {:#}, {:#?}",
29-
dev_info, auth_info
30-
);
31-
println!("Device info {:#}", dev_info);
25+
Ok(StatusUpdate::InteractiveManagement((tx, auth_info))) => {
26+
debug!("STATUS: interactive management: {:#?}", auth_info);
3227
let mut change_pin = false;
3328
if let Some(info) = auth_info {
3429
println!("Authenticator Info {:#?}", info);
@@ -98,27 +93,9 @@ fn interactive_status_callback(status_rx: Receiver<StatusUpdate>) {
9893
println!("Device only supports CTAP1 and can't be managed.");
9994
}
10095
}
101-
Ok(StatusUpdate::DeviceAvailable { dev_info }) => {
102-
num_of_devices += 1;
103-
debug!(
104-
"STATUS: New device #{} available: {}",
105-
num_of_devices, dev_info
106-
);
107-
}
108-
Ok(StatusUpdate::DeviceUnavailable { dev_info }) => {
109-
num_of_devices -= 1;
110-
if num_of_devices <= 0 {
111-
println!("No more devices left. Please plug in a device!");
112-
}
113-
debug!("STATUS: Device became unavailable: {}", dev_info)
114-
}
115-
Ok(StatusUpdate::Success { dev_info }) => {
116-
println!("STATUS: success using device: {}", dev_info);
117-
}
11896
Ok(StatusUpdate::SelectDeviceNotice) => {
11997
println!("STATUS: Please select a device by touching one of them.");
12098
}
121-
Ok(StatusUpdate::DeviceSelected(_dev_info)) => {}
12299
Ok(StatusUpdate::PresenceRequired) => {
123100
println!("STATUS: waiting for user presence");
124101
}

examples/reset.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ fn main() {
105105
manager.cancel().unwrap();
106106
return;
107107
}
108-
Ok(StatusUpdate::DeviceSelected(dev_info)) => {
109-
println!("STATUS: Continuing with device: {dev_info}");
110-
}
111108
Ok(StatusUpdate::PresenceRequired) => {
112109
println!("STATUS: waiting for user presence");
113110
break;

examples/set_pin.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,9 @@ fn main() {
7373
Ok(StatusUpdate::InteractiveManagement(..)) => {
7474
panic!("STATUS: This can't happen when doing non-interactive usage");
7575
}
76-
Ok(StatusUpdate::DeviceAvailable { dev_info }) => {
77-
println!("STATUS: device available: {dev_info}")
78-
}
79-
Ok(StatusUpdate::DeviceUnavailable { dev_info }) => {
80-
println!("STATUS: device unavailable: {dev_info}")
81-
}
82-
Ok(StatusUpdate::Success { dev_info }) => {
83-
println!("STATUS: success using device: {dev_info}");
84-
}
8576
Ok(StatusUpdate::SelectDeviceNotice) => {
8677
println!("STATUS: Please select a device by touching one of them.");
8778
}
88-
Ok(StatusUpdate::DeviceSelected(dev_info)) => {
89-
println!("STATUS: Continuing with device: {dev_info}");
90-
}
9179
Ok(StatusUpdate::PresenceRequired) => {
9280
println!("STATUS: waiting for user presence");
9381
}

examples/test_exclude_list.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,9 @@ fn main() {
8080
Ok(StatusUpdate::InteractiveManagement(..)) => {
8181
panic!("STATUS: This can't happen when doing non-interactive usage");
8282
}
83-
Ok(StatusUpdate::DeviceAvailable { dev_info }) => {
84-
println!("STATUS: device available: {dev_info}")
85-
}
86-
Ok(StatusUpdate::DeviceUnavailable { dev_info }) => {
87-
println!("STATUS: device unavailable: {dev_info}")
88-
}
89-
Ok(StatusUpdate::Success { dev_info }) => {
90-
println!("STATUS: success using device: {dev_info}");
91-
}
9283
Ok(StatusUpdate::SelectDeviceNotice) => {
9384
println!("STATUS: Please select a device by touching one of them.");
9485
}
95-
Ok(StatusUpdate::DeviceSelected(dev_info)) => {
96-
println!("STATUS: Continuing with device: {dev_info}");
97-
}
9886
Ok(StatusUpdate::PresenceRequired) => {
9987
println!("STATUS: waiting for user presence");
10088
}

src/ctap2/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,6 @@ pub fn register<Dev: FidoDevice>(
424424
let resp = dev.send_msg_cancellable(&makecred, alive);
425425
match resp {
426426
Ok(MakeCredentialsResult(attestation)) => {
427-
send_status(
428-
&status,
429-
crate::StatusUpdate::Success {
430-
dev_info: dev.get_device_info(),
431-
},
432-
);
433427
callback.call(Ok(RegisterResult::CTAP2(attestation)));
434428
return true;
435429
}
@@ -625,12 +619,6 @@ pub fn sign<Dev: FidoDevice>(
625619
}
626620
match resp {
627621
Ok(assertions) => {
628-
send_status(
629-
&status,
630-
crate::StatusUpdate::Success {
631-
dev_info: dev.get_device_info(),
632-
},
633-
);
634622
callback.call(Ok(SignResult::CTAP2(assertions)));
635623
return true;
636624
}
@@ -696,12 +684,6 @@ pub fn reset_helper(
696684
send_status(&status, crate::StatusUpdate::PresenceRequired);
697685
let resp = dev.send_cbor_cancellable(&reset, keep_alive);
698686
if resp.is_ok() {
699-
send_status(
700-
&status,
701-
crate::StatusUpdate::Success {
702-
dev_info: dev.get_device_info(),
703-
},
704-
);
705687
// The DeviceSelector could already be dead, but it might also wait
706688
// for us to respond, in order to cancel all other tokens in case
707689
// we skipped the "blinking"-action and went straight for the actual

src/statemachine.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ impl StateMachine {
104104
selector
105105
.send(DeviceSelectorEvent::ImAToken((dev.id(), tx)))
106106
.ok()?;
107-
send_status(
108-
status,
109-
crate::StatusUpdate::DeviceAvailable {
110-
dev_info: dev.get_device_info(),
111-
},
112-
);
113107

114108
// We can be cancelled from the user (through keep_alive()) or from the device selector
115109
// (through a DeviceCommand::Cancel on rx). We'll combine those signals into a single
@@ -130,11 +124,6 @@ impl StateMachine {
130124
selector
131125
.send(DeviceSelectorEvent::SelectedToken(dev.id()))
132126
.ok()?;
133-
134-
send_status(
135-
status,
136-
crate::StatusUpdate::DeviceSelected(dev.get_device_info()),
137-
);
138127
}
139128
BlinkResult::Cancelled => {
140129
info!("Device {:?} was not selected", dev.id());
@@ -148,20 +137,10 @@ impl StateMachine {
148137
}
149138
Ok(DeviceCommand::Removed) => {
150139
info!("Device {:?} was removed", dev.id());
151-
send_status(
152-
status,
153-
crate::StatusUpdate::DeviceUnavailable {
154-
dev_info: dev.get_device_info(),
155-
},
156-
);
157140
return None;
158141
}
159142
Ok(DeviceCommand::Continue) => {
160143
// Just continue
161-
send_status(
162-
status,
163-
crate::StatusUpdate::DeviceSelected(dev.get_device_info()),
164-
);
165144
}
166145
Err(_) => {
167146
warn!("Error when trying to receive messages from DeviceSelector! Exiting.");
@@ -432,13 +411,6 @@ impl StateMachine {
432411
return;
433412
}
434413

435-
send_status(
436-
&status,
437-
crate::StatusUpdate::DeviceAvailable {
438-
dev_info: dev.get_device_info(),
439-
},
440-
);
441-
442414
// Iterate the exclude list and see if there are any matches.
443415
// If so, we'll keep polling the device anyway to test for user
444416
// consent, to be consistent with CTAP2 device behavior.
@@ -476,22 +448,13 @@ impl StateMachine {
476448
break;
477449
}
478450
};
479-
let dev_info = dev.get_device_info();
480-
send_status(&status, crate::StatusUpdate::Success { dev_info });
481451
callback.call(Ok(RegisterResult::CTAP2(result)));
482452
break;
483453
}
484454

485455
// Sleep a bit before trying again.
486456
thread::sleep(Duration::from_millis(100));
487457
}
488-
489-
send_status(
490-
&status,
491-
crate::StatusUpdate::DeviceUnavailable {
492-
dev_info: dev.get_device_info(),
493-
},
494-
);
495458
},
496459
);
497460

@@ -566,13 +529,6 @@ impl StateMachine {
566529
return;
567530
}
568531

569-
send_status(
570-
&status,
571-
crate::StatusUpdate::DeviceAvailable {
572-
dev_info: dev.get_device_info(),
573-
},
574-
);
575-
576532
send_status(&status, crate::StatusUpdate::PresenceRequired);
577533

578534
'outer: while alive() {
@@ -611,8 +567,6 @@ impl StateMachine {
611567
break 'outer;
612568
}
613569
};
614-
let dev_info = dev.get_device_info();
615-
send_status(&status, crate::StatusUpdate::Success { dev_info });
616570
callback.call(Ok(SignResult::CTAP2(result)));
617571
break 'outer;
618572
}
@@ -622,13 +576,6 @@ impl StateMachine {
622576
// Sleep a bit before trying again.
623577
thread::sleep(Duration::from_millis(100));
624578
}
625-
626-
send_status(
627-
&status,
628-
crate::StatusUpdate::DeviceUnavailable {
629-
dev_info: dev.get_device_info(),
630-
},
631-
);
632579
},
633580
);
634581

@@ -673,7 +620,6 @@ impl StateMachine {
673620
&status,
674621
crate::StatusUpdate::InteractiveManagement((
675622
tx,
676-
dev.get_device_info(),
677623
dev.get_authenticator_info().cloned(),
678624
)),
679625
);

src/status_update.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{u2ftypes, Pin};
1+
use super::Pin;
22
use crate::ctap2::commands::get_info::AuthenticatorInfo;
33
use serde::{Deserialize, Serialize as DeriveSer, Serializer};
44
use std::sync::mpsc::Sender;
@@ -55,27 +55,17 @@ pub enum StatusPinUv {
5555

5656
#[derive(Debug)]
5757
pub enum StatusUpdate {
58-
/// Device found
59-
DeviceAvailable { dev_info: u2ftypes::U2FDeviceInfo },
60-
/// Device got removed
61-
DeviceUnavailable { dev_info: u2ftypes::U2FDeviceInfo },
6258
/// We're waiting for the user to touch their token
6359
PresenceRequired,
64-
/// We successfully finished the register or sign request
65-
Success { dev_info: u2ftypes::U2FDeviceInfo },
6660
/// Sent if a PIN is needed (or was wrong), or some other kind of PIN-related
6761
/// error occurred. The Sender is for sending back a PIN (if needed).
6862
PinUvError(StatusPinUv),
6963
/// Sent, if multiple devices are found and the user has to select one
7064
SelectDeviceNotice,
71-
/// Sent, once a device was selected (either automatically or by user-interaction)
72-
/// and the register or signing process continues with this device
73-
DeviceSelected(u2ftypes::U2FDeviceInfo),
7465
/// Sent when a token was selected for interactive management
7566
InteractiveManagement(
7667
(
7768
Sender<InteractiveRequest>,
78-
u2ftypes::U2FDeviceInfo,
7969
Option<AuthenticatorInfo>,
8070
),
8171
),

0 commit comments

Comments
 (0)