From 4e82028406ce58ccfebd11dab5c926e36c7fb5b3 Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Mon, 24 Nov 2025 07:29:45 -0600 Subject: [PATCH] Add UserId type --- .../win_webauthn/src/types/mod.rs | 51 ++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) 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 c892aac446b..e0b00c12436 100644 --- a/apps/desktop/desktop_native/win_webauthn/src/types/mod.rs +++ b/apps/desktop/desktop_native/win_webauthn/src/types/mod.rs @@ -498,7 +498,51 @@ pub(crate) struct WEBAUTHN_EXTENSIONS { pub(crate) pExtensions: *const WEBAUTHN_EXTENSION, } -struct CredentialId(Vec); +pub struct UserId(Vec); + +impl UserId { + pub fn len(&self) -> u8 { + // SAFETY: User ID guaranteed to be <= 64 bytes + self.0.len() as u8 + } +} +impl AsRef<[u8]> for UserId { + fn as_ref(&self) -> &[u8] { + &self.0 + } +} + +impl TryFrom> for UserId { + type Error = WinWebAuthnError; + + fn try_from(value: Vec) -> Result { + if value.len() > 64 { + return Err(WinWebAuthnError::new( + ErrorKind::Serialization, + &format!( + "User ID exceeds maximum length of 64, received {}", + value.len() + ), + )); + } + Ok(UserId(value)) + } +} + +pub struct CredentialId(Vec); + +impl CredentialId { + pub fn len(&self) -> u16 { + // SAFETY: CredentialId guaranteed to be < 1024 bytes + self.0.len() as u16 + } +} + +impl AsRef<[u8]> for CredentialId { + fn as_ref(&self) -> &[u8] { + &self.0 + } +} impl TryFrom> for CredentialId { type Error = WinWebAuthnError; @@ -517,11 +561,6 @@ impl TryFrom> for CredentialId { } } -impl AsRef<[u8]> for CredentialId { - fn as_ref(&self) -> &[u8] { - self.0.as_ref() - } -} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct WEBAUTHN_CREDENTIAL_EX {