pub struct CollectedClientData<'a> {
pub challenge: SentChallenge,
pub origin: Origin<'a>,
pub cross_origin: bool,
pub top_origin: Option<Origin<'a>>,
}Expand description
Fields§
§challenge: SentChallenge§origin: Origin<'a>§cross_origin: bool§top_origin: Option<Origin<'a>>When CollectedClientData is constructed via Self::from_client_data_json, this can only be
Some if Self::cross_origin; and if Some, it will be different than Self::origin.
Implementations§
Source§impl<'a> CollectedClientData<'a>
impl<'a> CollectedClientData<'a>
Sourcepub fn from_client_data_json<'b: 'a, const REGISTRATION: bool>(
json: &'b [u8],
) -> Result<Self, CollectedClientDataErr>
pub fn from_client_data_json<'b: 'a, const REGISTRATION: bool>( json: &'b [u8], ) -> Result<Self, CollectedClientDataErr>
Parses json based on the
limited verification algorithm.
Additionally, topOrigin is only
allowed to exist if it has a different value than
origin and
crossOrigin is true.
REGISTRATION iff type must be
"webauthn.create"; otherwise it must be "webauthn.get".
§Errors
Errors iff json cannot be parsed based on the aforementioned requirements.
§Examples
assert!(!CollectedClientData::from_client_data_json::<true>(br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.as_slice())?.cross_origin);
assert!(!CollectedClientData::from_client_data_json::<false>(br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.as_slice())?.cross_origin);Sourcepub fn from_client_data_json_relaxed<'b: 'a, const REGISTRATION: bool>(
json: &'b [u8],
) -> Result<Self, SerdeJsonErr>
Available on crate feature serde_relaxed only.
pub fn from_client_data_json_relaxed<'b: 'a, const REGISTRATION: bool>( json: &'b [u8], ) -> Result<Self, SerdeJsonErr>
serde_relaxed only.Parses json in a “relaxed” way.
Unlike Self::from_client_data_json which requires json to be an output from the
JSON-compatible serialization of client data,
this parses json based entirely on the
CollectedClientData Web IDL dictionary.
L1 clients predate the JSON-compatible serialization of client data; additionally there are L2 and L3
clients that don’t adhere to the JSON-compatible serialization of client data despite being required to.
These clients serialize CollectedClientData so that it’s valid JSON and conforms to the Web IDL dictionary
and nothing more. Furthermore, when not relying on the
limited verification algorithm, the spec
requires the data to be decoded in a way equivalent to
UTF-8 decode which both interprets a leading zero
width no-breaking space (i.e., U+FEFF) as a byte-order mark (BOM) as well as replaces any sequences of
invalid UTF-8 code units with the replacement character (i.e., U+FFFD). That is precisely what this
function does.
§Errors
Errors iff any of the following is true:
- The payload is not valid JSON after ignoring a leading U+FEFF and replacing any sequences of invalid UTF-8 code units with U+FFFD.
- The JSON does not conform to the Web IDL
dictionary. typeis not"webauthn.create"or"webauthn.get"whenREGISTRATIONand!REGISTRATIONrespectively.challengeis not a base64url-encodedChallenge.- Existence of duplicate keys for the keys that are expected.
§Examples
assert!(!CollectedClientData::from_client_data_json_relaxed::<true>(b"\xef\xbb\xbf{
\"type\": \"webauthn.create\",
\"origin\": \"https://example.com\",
\"f\xffo\": 123,
\"topOrigin\": \"https://example.com\",
\"challenge\": \"AAAAAAAAAAAAAAAAAAAAAA\"
}")?.cross_origin);