Skip to main content

CollectedClientData

Struct CollectedClientData 

Source
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>>

topOrigin.

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>

Source

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);
Source

pub fn from_client_data_json_relaxed<'b: 'a, const REGISTRATION: bool>( json: &'b [u8], ) -> Result<Self, SerdeJsonErr>

Available on crate feature 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.
  • type is not "webauthn.create" or "webauthn.get" when REGISTRATION and !REGISTRATION respectively.
  • challenge is not a base64url-encoded Challenge.
  • 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);

Trait Implementations§

Source§

impl<'a> Debug for CollectedClientData<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.