Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
working-directory: build/

- name: Check clippy recommendations
run: cargo clippy --locked --workspace --all-features --target-dir build/target
run: cargo clippy --locked --workspace --all-features --target-dir build/target -- -Dwarnings

- name: Check formatting
run: cargo fmt --all --check
4 changes: 2 additions & 2 deletions credentialsd-common/src/memfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ impl Mmap {
.ok_or_else(|| io::Error::other("mmap returned NULL pointer"))?
};

return Ok(Self {
Ok(Self {
inner: ptr,
fd,
size,
pos: 0,
});
})
}

fn into_fd(self) -> OwnedFd {
Expand Down
5 changes: 2 additions & 3 deletions credentialsd-common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ impl TryFrom<&Structure<'_>> for BackgroundEvent {
.iter()
.map(|v| v.try_to_owned().unwrap())
.map(|v| {
let cred: Result<Credential, zvariant::Error> = Value::from(v)
.downcast::<Credential>()
.map(Credential::from);
let cred: Result<Credential, zvariant::Error> =
Value::from(v).downcast::<Credential>();
cred
})
.collect();
Expand Down
6 changes: 4 additions & 2 deletions credentialsd-ui/src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub(crate) struct UiContext {
/// These methods are called by the credential service to control the UI.
#[interface(name = "org.freedesktop.impl.portal.experimental.Credential")]
impl CredentialPortalBackend {
// D-Bus has long argument signatures.
#[expect(clippy::too_many_arguments)]
async fn initialize(
&self,
#[zbus(connection)] connection: &Connection,
Expand Down Expand Up @@ -277,7 +279,7 @@ impl CeremonyObject {
pid: self.ui_context.app_pid,
},
initial_devices: self.ui_context.devices.clone(),
window_handle: self.ui_context.parent_window.clone().into(),
window_handle: self.ui_context.parent_window.clone(),
},
Arc::new(AsyncMutex::new(flow_control_client)),
cancel_rx,
Expand All @@ -302,7 +304,7 @@ impl CeremonyObject {
} else {
tracing::error!("Flow was not properly initialized before receiving events.");
}
return Err(fdo::Error::Failed("Failed to handle event".to_string()));
Err(fdo::Error::Failed("Failed to handle event".to_string()))
}

#[zbus(signal)]
Expand Down
8 changes: 4 additions & 4 deletions credentialsd-ui/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fn run_gui(
let (tx_event, rx_event) = async_std::channel::unbounded::<ViewEvent>();
let tx_event2 = tx_event.clone();
let cancel_task = async_std::task::spawn(async move {
if let Ok(_) = cancel_rx.recv().await {
if tx_event2.send(ViewEvent::UserCancelled).await.is_err() {
tracing::error!("Failed to send cancellation to view model");
}
if let Ok(_) = cancel_rx.recv().await
&& tx_event2.send(ViewEvent::UserCancelled).await.is_err()
{
tracing::error!("Failed to send cancellation to view model");
}
});
let event_loop = async_std::task::spawn(async move {
Expand Down
8 changes: 4 additions & 4 deletions credentialsd-ui/src/gui/view_model/gtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl ViewModel {
let localized = ngettext(
"Enter your PIN. One attempt remaining.",
"Enter your PIN. %d attempts remaining.",
left.into(),
left,
);
localized.replace("%d", &format!("{}", left))
} else {
Expand All @@ -173,7 +173,7 @@ impl ViewModel {
let localized = ngettext(
"Touch your device again. One attempt remaining.",
"Touch your device again. %d attempts remaining.",
left.into(),
left,
);
localized.replace("%d", &format!("{}", left))
}
Expand All @@ -192,7 +192,7 @@ impl ViewModel {
}
ViewUpdate::HybridConnecting => {
view_model.set_qr_code_visible(false);
_ = view_model.qr_code_paintable().take();
_ = view_model.qr_code_paintable();
view_model.waiting_for_device(&Device {
id: "x".to_string(),
transport: Transport::HybridQr,
Expand All @@ -204,7 +204,7 @@ impl ViewModel {
}
ViewUpdate::HybridConnected => {
view_model.set_qr_code_visible(false);
_ = view_model.qr_code_paintable().take();
_ = view_model.qr_code_paintable();
view_model.set_prompt(gettext(
"Device connected. Follow the instructions on your device",
));
Expand Down
15 changes: 7 additions & 8 deletions credentialsd-ui/src/gui/view_model/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ mod imp {
impl WindowImpl for CredentialsUiWindow {
// Save window state on delete event
fn close_request(&self) -> glib::Propagation {
if let Some(vm) = self.view_model.borrow().as_ref() {
if vm
if let Some(vm) = self.view_model.borrow().as_ref()
&& vm
.get_sender()
.send_blocking(ViewEvent::UserCancelled)
.is_err()
{
tracing::warn!(
"Failed to notify the backend service that the user cancelled the request."
);
};
}
{
tracing::warn!(
"Failed to notify the backend service that the user cancelled the request."
);
};

// Pass close request on to the parent
self.parent_close_request()
Expand Down
2 changes: 1 addition & 1 deletion credentialsd/src/credential_service/nfc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl From<&NfcState> for BackgroundEvent {
}
}
NfcState::SelectingCredential { creds, .. } => BackgroundEvent::SelectingCredential {
creds: creds.to_owned().into_iter().map(|c| c.into()).collect(),
creds: creds.to_vec(),
},
NfcState::Completed => BackgroundEvent::CeremonyCompleted,
NfcState::Failed(Error::AuthenticatorError) => BackgroundEvent::ErrorAuthenticator,
Expand Down
2 changes: 1 addition & 1 deletion credentialsd/src/credential_service/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl From<&UsbState> for BackgroundEvent {
}
UsbState::NeedsUserPresence => BackgroundEvent::NeedsUserPresence,
UsbState::SelectingCredential { creds, .. } => BackgroundEvent::SelectingCredential {
creds: creds.to_owned().into_iter().map(|c| c.into()).collect(),
creds: creds.to_vec(),
},
UsbState::Completed => BackgroundEvent::CeremonyCompleted,
UsbState::Failed(Error::AuthenticatorError) => BackgroundEvent::ErrorAuthenticator,
Expand Down
8 changes: 4 additions & 4 deletions credentialsd/src/dbus/flow_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn start_flow_control_service<M: ManageDevice + Debug + Send + Sync +
activation_token,
)
.await;
if let Err(_) = response_channel.send(response) {
if response_channel.send(response).is_err() {
tracing::error!(
"Received response to credential request, but failed to forward it to gateway"
);
Expand Down Expand Up @@ -179,7 +179,7 @@ async fn handle<M: ManageDevice + Debug + Send + Sync + 'static, UC: UiControlle
}
UserInteractedEvent::ClientPinEntered(pin_fd) => {
let pin_fd = OwnedFd::from(pin_fd);
let pin = match read_secret(pin_fd.into())
let pin = match read_secret(pin_fd)
.map_err(|err| format!("Could not read from file descriptor: {err}"))
.and_then(|bytes| {
String::from_utf8(bytes).map_err(|err| {
Expand Down Expand Up @@ -227,8 +227,8 @@ async fn handle<M: ManageDevice + Debug + Send + Sync + 'static, UC: UiControlle
let cred_response = request_rx
.await
.expect("Credential service not to drop request channel before responding.");
let f = cred_response.map_err(|err| err.into());
f

cred_response
}

fn forward_background_event_stream(
Expand Down
6 changes: 5 additions & 1 deletion credentialsd/src/dbus/ui_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use credentialsd_common::model::{

/// Used by the credential service to control the UI.
pub trait UiController {
// D-Bus has a lot of arguments
#[expect(clippy::too_many_arguments)]
fn initialize(
&self,
handle: OwnedObjectPath,
Expand All @@ -39,6 +41,8 @@ pub trait UiController {
default_path = "/org/freedesktop/portal/desktop"
)]
trait UiControlService2 {
// D-Bus has a lot of arguments
#[expect(clippy::too_many_arguments)]
fn initialize(
&self,
handle: ObjectPath<'_>,
Expand Down Expand Up @@ -153,7 +157,7 @@ async fn forward_ui_events(
while let Some(signal) = ui_event_stream.next().await {
tracing::trace!(?signal, "Received event from UI");
let event = signal.args()?.update;
if let Err(_) = tx.send(event).await {
if tx.send(event).await.is_err() {
tracing::trace!("credential service event listener stopped listening for UI events. Ending event stream listener");
break;
}
Expand Down
22 changes: 7 additions & 15 deletions credentialsd/src/gateway/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct CredentialPortalGateway {
/// The D-Bus interface is responsible for authorizing the client and collecting
/// the contextual information about the client to pass onto the GatewayService
/// for evaluation.
// D-Bus has long argument signatures.
#[expect(clippy::too_many_arguments)]
#[interface(name = "org.freedesktop.handler.portal.experimental.Credential")]
impl CredentialPortalGateway {
#[zbus(out_args("response", "results"))]
Expand Down Expand Up @@ -87,7 +89,7 @@ impl CredentialPortalGateway {
&header,
claimed_app_id,
origin.clone(),
top_origin.clone().into(),
top_origin.clone(),
)
.await;
let context = match app_validation_result {
Expand All @@ -111,12 +113,7 @@ impl CredentialPortalGateway {
.gateway_service
.lock()
.await
.handle_create_credential(
request,
context,
parent_window.into(),
activation_token.into(),
)
.handle_create_credential(request, context, parent_window.into(), activation_token)
.await
.map_err(Error::from);

Expand All @@ -143,7 +140,7 @@ impl CredentialPortalGateway {
&header,
claimed_app_id,
origin.clone(),
top_origin.clone().into(),
top_origin.clone(),
)
.await;

Expand Down Expand Up @@ -172,12 +169,7 @@ impl CredentialPortalGateway {
.gateway_service
.lock()
.await
.handle_get_credential(
request,
context,
parent_window.into(),
activation_token.into(),
)
.handle_get_credential(request, context, parent_window.into(), activation_token)
.await
.map_err(Error::from);
response.into()
Expand Down Expand Up @@ -292,7 +284,7 @@ impl From<WebAuthnError> for Error {
#[derive(Serialize)]
enum PortalResponse {
Success = 0,
Cancelled = 1,
// Cancelled = 1,
Other = 2,
}

Expand Down
6 changes: 4 additions & 2 deletions credentialsd/src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ async fn should_trust_app_id(pid: u32) -> bool {
);
if !trusted_callers.as_slice().contains(&exe_path) {
tracing::warn!(?exe_path, "Request received from untrusted caller");
return false;
false
} else {
return true;
true
}
}

Expand Down Expand Up @@ -426,6 +426,8 @@ impl From<CreatePublicKeyCredentialResponse> for CreateCredentialResponse {
}
}

// We want to keep these aligned with how the spec names them.
#[expect(clippy::enum_variant_names)]
#[derive(Debug)]
pub enum WebAuthnError {
/// The ceremony was cancelled by an AbortController. See § 5.6 Abort
Expand Down
Loading
Loading