use serde::Serialize; /// A trait describing how client data should be generated during a WebAuthn operation. pub trait ClientData { /// Extra client data to be appended to the automatically generated client data. fn extra_client_data(&self) -> E; /// The hash of the client data to be used in the WebAuthn operation. fn client_data_hash(&self) -> Option>; } /// The client data and its hash will be automatically generated from the request /// according to the WebAuthn specification. pub struct DefaultClientData; impl ClientData<()> for DefaultClientData { fn extra_client_data(&self) {} fn client_data_hash(&self) -> Option> { None } } /// The extra client data will be appended to the automatically generated client data. /// The hash will be automatically generated from the result client data according to the WebAuthn specification. pub struct DefaultClientDataWithExtra(pub E); impl ClientData for DefaultClientDataWithExtra { fn extra_client_data(&self) -> E { self.0.clone() } fn client_data_hash(&self) -> Option> { None } } /// The client data will be automatically generated from the request according to the WebAuthn specification /// but it will not be used as a base for the hash. The client data hash will instead be provided by the caller. pub struct DefaultClientDataWithCustomHash(pub Vec); impl ClientData<()> for DefaultClientDataWithCustomHash { fn extra_client_data(&self) {} fn client_data_hash(&self) -> Option> { Some(self.0.clone()) } } /// Backwards compatibility with the previous `register` and `authenticate` functions /// which only took `Option>` as a client data hash. impl ClientData<()> for Option> { fn extra_client_data(&self) {} fn client_data_hash(&self) -> Option> { self.clone() } }