Repository navigation
Display error/reason to user, if a transport had to be restarted #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
42ce2f7
b9e8425
852e47b
52cb851
8a2627c
322e4be
32e1e76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,53 @@ pub const BACKGROUND_EVENT_ERROR_INTERNAL: u32 = 0x80000001; | |
| pub const BACKGROUND_EVENT_ERROR_TIMED_OUT: u32 = 0x80000002; | ||
| pub const BACKGROUND_EVENT_ERROR_CANCELLED: u32 = 0x80000003; | ||
| pub const BACKGROUND_EVENT_ERROR_AUTHENTICATOR: u32 = 0x80000004; | ||
| pub const BACKGROUND_EVENT_ERROR_NO_CREDENTIALS: u32 = 0x80000005; | ||
| pub const BACKGROUND_EVENT_ERROR_CREDENTIAL_EXCLUDED: u32 = 0x80000006; | ||
| pub const BACKGROUND_EVENT_ERROR_PIN_ATTEMPTS_EXHAUSTED: u32 = 0x80000007; | ||
| pub const BACKGROUND_EVENT_ERROR_PIN_NOT_SET: u32 = 0x80000008; | ||
|
|
||
| /// Machine-readable reason for a transport restart. Shared across all transports. | ||
| /// Human-readable strings are built by the UI (gettext). | ||
| /// | ||
| /// The `#[repr(u8)]` layout doubles as the D-Bus wire format via `From<Self> for u8` | ||
| /// and `TryFrom<u8> for Self`. Discriminants must remain stable across releases. | ||
| /// Discriminant 0 is deliberately unused so that an all-zeroed message is recognisable | ||
| /// as invalid by `TryFrom`. | ||
| #[repr(u8)] | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum TransportRestartReason { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're currently using PascalCase strings to communicate enums everywhere else in the API. I find that easier to read in D-Bus output while debugging, and the extra 10 or so bytes in the message doesn't hurt. Do you have opinions either way? If not, I'd recommend to make this a string for consistency.
Comment on lines
+12
to
+22
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this enum down so that members are ordered alphabetically? |
||
| /// The ceremony was interrupted before completing — transport error, | ||
| /// user cancelled on their phone/device, or an unrecoverable authenticator | ||
| /// error. The user should follow the new prompts to retry. | ||
| Interrupted = 1, | ||
| /// No matching credentials were found on the device. The user should try | ||
| /// a different authenticator. | ||
| NoCredentials = 2, | ||
| /// Too many incorrect PIN attempts on this device — it is now locked. The | ||
| /// user should remove and reinsert the device, or use a different authenticator. | ||
| PinAttemptsExhausted = 3, | ||
| /// The transport failed repeatedly before the user interacted with it and | ||
| /// stopped for the rest of this request; it will not restart. The UI should | ||
| /// stop offering it. The other transports keep running. | ||
| TransportUnavailable = 4, | ||
| } | ||
|
|
||
| impl From<TransportRestartReason> for u8 { | ||
| fn from(value: TransportRestartReason) -> Self { | ||
| value as u8 | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<u8> for TransportRestartReason { | ||
| type Error = u8; | ||
|
|
||
| fn try_from(value: u8) -> Result<Self, Self::Error> { | ||
| match value { | ||
| 1 => Ok(Self::Interrupted), | ||
| 2 => Ok(Self::NoCredentials), | ||
| 3 => Ok(Self::PinAttemptsExhausted), | ||
| 4 => Ok(Self::TransportUnavailable), | ||
| other => Err(other), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Credential service events intended to inform the UI. | ||
| #[derive(Debug, PartialEq)] | ||
|
|
@@ -37,34 +80,40 @@ pub enum BackgroundEvent { | |
| HybridConnected, | ||
| /// The hybrid ceremony was interrupted by a non-terminating error and a new | ||
| /// QR code is about to be issued. The UI should navigate back to the start | ||
| /// page so the new QR becomes visible. | ||
| HybridRestarting, | ||
| /// page so the new QR becomes visible. With `TransportUnavailable`, hybrid | ||
| /// stopped instead and the UI should stop offering it. | ||
| HybridRestarting { | ||
| reason: TransportRestartReason, | ||
| }, | ||
|
|
||
| NfcIdle, | ||
| NfcWaiting, | ||
| NfcConnected, | ||
| /// The NFC ceremony was interrupted by a non-terminating error and the | ||
| /// transport is polling for a new device tap. The UI should navigate back | ||
| /// to the start page. | ||
| NfcRestarting, | ||
| /// to the start page. With `TransportUnavailable`, NFC stopped instead and | ||
| /// the UI should stop offering it. | ||
| NfcRestarting { | ||
| reason: TransportRestartReason, | ||
| }, | ||
|
|
||
| UsbIdle, | ||
| UsbWaiting, | ||
| UsbSelectingDevice, | ||
| UsbConnected, | ||
| /// The USB ceremony was interrupted by a non-terminating error and the | ||
| /// transport is polling for a device. The UI should navigate back to the | ||
| /// start page. | ||
| UsbRestarting, | ||
| /// start page. With `TransportUnavailable`, USB stopped instead and the UI | ||
| /// should stop offering it. | ||
| UsbRestarting { | ||
| reason: TransportRestartReason, | ||
| }, | ||
|
|
||
| ErrorInternal, | ||
| ErrorTimedOut, | ||
| ErrorCancelled, | ||
| ErrorAuthenticator, | ||
| ErrorNoCredentials, | ||
| ErrorCredentialExcluded, | ||
| ErrorPinAttemptsExhausted, | ||
| ErrorPinNotSet, | ||
| } | ||
|
|
||
| /// Emitted when a client enters a PIN for the selected authenticator. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need to move these up to the unreleased section