From 979f59a3835c7e85aeade855a682bf4aab3e19a3 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Fri, 19 Dec 2025 08:25:03 -0600 Subject: [PATCH] Address Clippy lints --- .../win_webauthn/src/plugin/com.rs | 19 ++++++++----------- .../win_webauthn/src/plugin/types.rs | 5 ++--- .../win_webauthn/src/types/mod.rs | 18 +++++++++++++++--- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs b/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs index 8da3d4a7599..9bfcfda1c11 100644 --- a/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs +++ b/apps/desktop/desktop_native/win_webauthn/src/plugin/com.rs @@ -135,7 +135,7 @@ impl IPluginAuthenticator_Impl for PluginAuthenticatorComObject_Impl { tracing::error!( "Failed to write MakeCredential response to Windows: {err}" ); - return E_FAIL; + E_FAIL } } } @@ -193,7 +193,7 @@ impl IPluginAuthenticator_Impl for PluginAuthenticatorComObject_Impl { } Err(err) => { tracing::error!("Failed to write GetCredential response to Windows: {err}"); - return E_FAIL; + E_FAIL } } } @@ -375,12 +375,13 @@ impl ComBuffer { // SAFETY: Any size is valid to pass to Windows, even `0`. let ptr = NonNull::new(unsafe { CoTaskMemAlloc(size) }).unwrap_or_else(|| { // XXX: This doesn't have to be correct, just close enough for an OK OOM error. - let layout = alloc::Layout::from_size_align(size, align_of::()).unwrap(); + let layout = alloc::Layout::from_size_align(size, align_of::()) + .expect("size of u8 to always be aligned"); alloc::handle_alloc_error(layout) }); if for_slice { - // Ininitialize the buffer so it can later be treated as `&mut [u8]`. + // Initialize the buffer so it can later be treated as `&mut [u8]`. // SAFETY: The pointer is valid and we are using a valid value for a byte-wise // allocation. unsafe { ptr.write_bytes(0, size) }; @@ -412,18 +413,14 @@ impl ComBufferExt for &[u8] { impl ComBufferExt for Vec { fn to_com_buffer(&self) -> ComBuffer { - let buffer: Vec = self.into_iter().flat_map(|x| x.to_le_bytes()).collect(); + let buffer: Vec = self.iter().flat_map(|x| x.to_le_bytes()).collect(); ComBuffer::from(&buffer) } } impl ComBufferExt for &[u16] { fn to_com_buffer(&self) -> ComBuffer { - let buffer: Vec = self - .as_ref() - .into_iter() - .flat_map(|x| x.to_le_bytes()) - .collect(); + let buffer: Vec = self.as_ref().iter().flat_map(|x| x.to_le_bytes()).collect(); ComBuffer::from(&buffer) } } @@ -432,7 +429,7 @@ impl> From for ComBuffer { fn from(value: T) -> Self { let buffer: Vec = value .as_ref() - .into_iter() + .iter() .flat_map(|x| x.to_le_bytes()) .collect(); let len = buffer.len(); diff --git a/apps/desktop/desktop_native/win_webauthn/src/plugin/types.rs b/apps/desktop/desktop_native/win_webauthn/src/plugin/types.rs index d911e5b99c6..ae06266141e 100644 --- a/apps/desktop/desktop_native/win_webauthn/src/plugin/types.rs +++ b/apps/desktop/desktop_native/win_webauthn/src/plugin/types.rs @@ -144,13 +144,13 @@ impl PluginAddAuthenticatorOptions { pub(super) fn light_theme_logo_b64(&self) -> Option> { self.light_theme_logo_svg .as_ref() - .map(|svg| Self::encode_svg(&svg)) + .map(|svg| Self::encode_svg(svg)) } pub(super) fn dark_theme_logo_b64(&self) -> Option> { self.dark_theme_logo_svg .as_ref() - .map(|svg| Self::encode_svg(&svg)) + .map(|svg| Self::encode_svg(svg)) } fn encode_svg(svg: &str) -> Vec { @@ -199,7 +199,6 @@ impl PluginAddAuthenticatorResponse { pub(super) unsafe fn try_from_ptr( value: NonNull, ) -> Self { - if value.as_ref().pbOpSignPubKey.is_null() {} Self { inner: value } } } diff --git a/apps/desktop/desktop_native/win_webauthn/src/types/mod.rs b/apps/desktop/desktop_native/win_webauthn/src/types/mod.rs index 1fc9c3b29fd..bb6139d54aa 100644 --- a/apps/desktop/desktop_native/win_webauthn/src/types/mod.rs +++ b/apps/desktop/desktop_native/win_webauthn/src/types/mod.rs @@ -491,6 +491,8 @@ pub(crate) struct WEBAUTHN_EXTENSION { pvExtension: *mut u8, } +// These names follow the naming convention in the Windows API. +#[allow(clippy::enum_variant_names)] pub enum CredProtectOutput { UserVerificationAny, UserVerificationOptional, @@ -517,6 +519,8 @@ pub(crate) struct WEBAUTHN_EXTENSIONS { pub struct UserId(Vec); impl UserId { + // User IDs cannot be empty + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> u8 { // SAFETY: User ID guaranteed to be <= 64 bytes self.0.len() as u8 @@ -532,6 +536,12 @@ impl TryFrom> for UserId { type Error = WinWebAuthnError; fn try_from(value: Vec) -> Result { + if value.is_empty() { + return Err(WinWebAuthnError::new( + ErrorKind::Serialization, + "User ID cannot be empty", + )); + } if value.len() > 64 { return Err(WinWebAuthnError::new( ErrorKind::Serialization, @@ -549,6 +559,8 @@ impl TryFrom> for UserId { pub struct CredentialId(Vec); impl CredentialId { + // Credential IDs cannot be empty + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> u16 { // SAFETY: CredentialId guaranteed to be < 1024 bytes self.0.len() as u16 @@ -565,11 +577,11 @@ impl TryFrom> for CredentialId { type Error = WinWebAuthnError; fn try_from(value: Vec) -> Result { - if value.len() > 1023 { + if value.len() < 16 || value.len() > 1023 { return Err(WinWebAuthnError::new( ErrorKind::Serialization, &format!( - "Credential ID exceeds maximum length of 1023, received {}", + "Credential ID must be between 16 and 1023 bytes long, received {}", value.len() ), )); @@ -646,7 +658,7 @@ impl CredentialEx<'_> { break; } if a as u32 & t > 0 { - transports.push(a.clone()); + transports.push(a); t -= a as u32; } }