diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/rust/authenticator/src/status_update.rs | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/authenticator/src/status_update.rs')
-rw-r--r-- | third_party/rust/authenticator/src/status_update.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/third_party/rust/authenticator/src/status_update.rs b/third_party/rust/authenticator/src/status_update.rs new file mode 100644 index 0000000000..f01cbd0cea --- /dev/null +++ b/third_party/rust/authenticator/src/status_update.rs @@ -0,0 +1,89 @@ +use super::{u2ftypes, Pin}; +use crate::ctap2::commands::get_info::AuthenticatorInfo; +use serde::{Deserialize, Serialize as DeriveSer, Serializer}; +use std::sync::mpsc::Sender; + +#[derive(Debug, Deserialize, DeriveSer)] +pub enum InteractiveRequest { + Reset, + ChangePIN(Pin, Pin), + SetPIN(Pin), +} + +// Simply ignoring the Sender when serializing +pub(crate) fn serialize_pin_required<S>(_: &Sender<Pin>, s: S) -> Result<S::Ok, S::Error> +where + S: Serializer, +{ + s.serialize_none() +} + +// Simply ignoring the Sender when serializing +pub(crate) fn serialize_pin_invalid<S>( + _: &Sender<Pin>, + retries: &Option<u8>, + s: S, +) -> Result<S::Ok, S::Error> +where + S: Serializer, +{ + if let Some(r) = retries { + s.serialize_u8(*r) + } else { + s.serialize_none() + } +} + +#[derive(Debug, DeriveSer)] +pub enum StatusPinUv { + #[serde(serialize_with = "serialize_pin_required")] + PinRequired(Sender<Pin>), + #[serde(serialize_with = "serialize_pin_invalid")] + InvalidPin(Sender<Pin>, Option<u8>), + PinIsTooShort, + PinIsTooLong(usize), + InvalidUv(Option<u8>), + // This SHOULD ever only happen for CTAP2.0 devices that + // use internal UV (e.g. fingerprint sensors) and failed (e.g. wrong + // finger used). + // PinAuthInvalid, // Folded into InvalidUv + PinAuthBlocked, + PinBlocked, + PinNotSet, + UvBlocked, +} + +#[derive(Debug)] +pub enum StatusUpdate { + /// Device found + DeviceAvailable { dev_info: u2ftypes::U2FDeviceInfo }, + /// Device got removed + DeviceUnavailable { dev_info: u2ftypes::U2FDeviceInfo }, + /// We're waiting for the user to touch their token + PresenceRequired, + /// We successfully finished the register or sign request + Success { dev_info: u2ftypes::U2FDeviceInfo }, + /// Sent if a PIN is needed (or was wrong), or some other kind of PIN-related + /// error occurred. The Sender is for sending back a PIN (if needed). + PinUvError(StatusPinUv), + /// Sent, if multiple devices are found and the user has to select one + SelectDeviceNotice, + /// Sent, once a device was selected (either automatically or by user-interaction) + /// and the register or signing process continues with this device + DeviceSelected(u2ftypes::U2FDeviceInfo), + /// Sent when a token was selected for interactive management + InteractiveManagement( + ( + Sender<InteractiveRequest>, + u2ftypes::U2FDeviceInfo, + Option<AuthenticatorInfo>, + ), + ), +} + +pub(crate) fn send_status(status: &Sender<StatusUpdate>, msg: StatusUpdate) { + match status.send(msg) { + Ok(_) => {} + Err(e) => error!("Couldn't send status: {:?}", e), + }; +} |