From 0a66b2c0f52319f3157b5483072aee17c5baae59 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Thu, 18 Dec 2025 13:41:54 -0600 Subject: [PATCH] Remove wrapping Result, return slice directly based on safety constraints --- .../win_webauthn/src/plugin/types.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 7729a5d56ce..c9a4b4690a3 100644 --- a/apps/desktop/desktop_native/win_webauthn/src/plugin/types.rs +++ b/apps/desktop/desktop_native/win_webauthn/src/plugin/types.rs @@ -451,18 +451,16 @@ pub struct PluginMakeCredentialRequest { } impl PluginMakeCredentialRequest { - pub fn client_data_hash(&self) -> Result<&[u8], WinWebAuthnError> { - if self.as_ref().cbClientDataHash == 0 || self.as_ref().pbClientDataHash.is_null() { - return Err(WinWebAuthnError::new( - ErrorKind::WindowsInternal, - "Received invalid client data hash", - )); - } + pub fn client_data_hash(&self) -> &[u8] { + // SAFETY: clientDataHash is a required field, and when this is + // constructed using Self::try_from_ptr(), the Windows decode API + // constructs valid pointers. unsafe { - Ok(std::slice::from_raw_parts( + std::slice::from_raw_parts( self.as_ref().pbClientDataHash, + // SAFETY: we only support Windows versions where usize >= 32 self.as_ref().cbClientDataHash as usize, - )) + ) } }