use crate::error::DiscoverError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WebAuthnChallenge {
pub url: String,
pub is_registration: bool,
}
pub fn discover_webauthn_challenge(
url: &str,
html: &str,
) -> Result<Option<WebAuthnChallenge>, DiscoverError> {
if html.is_empty() {
return Err(DiscoverError::Parse("empty html document".to_string()));
}
let is_registration = html.contains("navigator.credentials.create");
let is_authentication = html.contains("navigator.credentials.get");
if is_registration || is_authentication {
Ok(Some(WebAuthnChallenge {
url: url.to_string(),
is_registration,
}))
} else {
Ok(None)
}
}