1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-30 16:23:53 +00:00

Address Clippy lints

This commit is contained in:
Isaiah Inuwa
2025-12-19 08:25:03 -06:00
parent 79017cd761
commit 979f59a383
3 changed files with 25 additions and 17 deletions

View File

@@ -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::<u8>()).unwrap();
let layout = alloc::Layout::from_size_align(size, align_of::<u8>())
.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<u16> {
fn to_com_buffer(&self) -> ComBuffer {
let buffer: Vec<u8> = self.into_iter().flat_map(|x| x.to_le_bytes()).collect();
let buffer: Vec<u8> = 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<u8> = self
.as_ref()
.into_iter()
.flat_map(|x| x.to_le_bytes())
.collect();
let buffer: Vec<u8> = self.as_ref().iter().flat_map(|x| x.to_le_bytes()).collect();
ComBuffer::from(&buffer)
}
}
@@ -432,7 +429,7 @@ impl<T: AsRef<[u8]>> From<T> for ComBuffer {
fn from(value: T) -> Self {
let buffer: Vec<u8> = value
.as_ref()
.into_iter()
.iter()
.flat_map(|x| x.to_le_bytes())
.collect();
let len = buffer.len();

View File

@@ -144,13 +144,13 @@ impl PluginAddAuthenticatorOptions {
pub(super) fn light_theme_logo_b64(&self) -> Option<Vec<u16>> {
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<Vec<u16>> {
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<u16> {
@@ -199,7 +199,6 @@ impl PluginAddAuthenticatorResponse {
pub(super) unsafe fn try_from_ptr(
value: NonNull<WebAuthnPluginAddAuthenticatorResponse>,
) -> Self {
if value.as_ref().pbOpSignPubKey.is_null() {}
Self { inner: value }
}
}

View File

@@ -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<u8>);
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<Vec<u8>> for UserId {
type Error = WinWebAuthnError;
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
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<Vec<u8>> for UserId {
pub struct CredentialId(Vec<u8>);
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<Vec<u8>> for CredentialId {
type Error = WinWebAuthnError;
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
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;
}
}