pub struct CredentialsMemoryStorage<Id, Secret>where
Id: Hash,{ /* private fields */ }
Expand description
Stores credentials in memory for authentication.
For simplicity, this storage does implement both CredentialsStorageService as well as CredentialsVerifierService.
§Create and use a credential storage for authentication
let hasher = Argon2Hasher::default();
// Lets assume the user id is an email address and the user has a gooood password.
let creds = Credentials::new("admin@example.com", "admin_password".as_bytes())
.hash_secret(&hasher)
.unwrap();
let creds_to_verify = Credentials::new("admin@example.com", "admin_password".as_bytes().to_vec());
// In order to enable user verification we need to store a hashed version in our pre-defined
// memory storage.
let creds_storage = CredentialsMemoryStorage::from(vec![creds.clone()]);
assert_eq!(true, creds_storage.verify_credentials(&creds_to_verify, &hasher).await.unwrap());
let false_creds = Credentials::new("admin@example.com", "crazysecret".as_bytes())
.hash_secret(&hasher).unwrap();
assert_eq!(false, creds_storage.verify_credentials(&false_creds, &hasher).await.unwrap());
Trait Implementations§
Source§impl<Id, Secret: Clone> Clone for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret: Clone> Clone for CredentialsMemoryStorage<Id, Secret>
Source§fn clone(&self) -> CredentialsMemoryStorage<Id, Secret>
fn clone(&self) -> CredentialsMemoryStorage<Id, Secret>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<Id, Secret> CredentialsStorageService<Id, Secret> for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret> CredentialsStorageService<Id, Secret> for CredentialsMemoryStorage<Id, Secret>
Source§async fn store_credentials(
&self,
credentials: Credentials<Id, Secret>,
) -> Result<bool, Error>
async fn store_credentials( &self, credentials: Credentials<Id, Secret>, ) -> Result<bool, Error>
Source§async fn remove_credentials(
&self,
credentials: Credentials<Id, Secret>,
) -> Result<bool, Error>
async fn remove_credentials( &self, credentials: Credentials<Id, Secret>, ) -> Result<bool, Error>
Source§async fn update_credentials(
&self,
credentials: Credentials<Id, Secret>,
) -> Result<(), Error>
async fn update_credentials( &self, credentials: Credentials<Id, Secret>, ) -> Result<(), Error>
Updates the credentials.
Source§impl<Id, Secret> CredentialsVerifierService<Id, Secret> for CredentialsMemoryStorage<Id, Vec<u8>>
impl<Id, Secret> CredentialsVerifierService<Id, Secret> for CredentialsMemoryStorage<Id, Vec<u8>>
Source§async fn verify_credentials<Hasher>(
&self,
credentials: &Credentials<Id, Secret>,
hasher: &Hasher,
) -> Result<bool, Error>where
Hasher: SecretsHashingService,
async fn verify_credentials<Hasher>(
&self,
credentials: &Credentials<Id, Secret>,
hasher: &Hasher,
) -> Result<bool, Error>where
Hasher: SecretsHashingService,
Returns
true
if the given secret matches the one in your secret storage.Source§impl<Id, Secret> Default for CredentialsMemoryStorage<Id, Secret>where
Id: Hash,
impl<Id, Secret> Default for CredentialsMemoryStorage<Id, Secret>where
Id: Hash,
Source§impl<Id, Secret> From<Vec<Credentials<Id, Secret>>> for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret> From<Vec<Credentials<Id, Secret>>> for CredentialsMemoryStorage<Id, Secret>
Source§fn from(value: Vec<Credentials<Id, Secret>>) -> Self
fn from(value: Vec<Credentials<Id, Secret>>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<Id, Secret> Freeze for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret> !RefUnwindSafe for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret> Send for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret> Sync for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret> Unpin for CredentialsMemoryStorage<Id, Secret>
impl<Id, Secret> !UnwindSafe for CredentialsMemoryStorage<Id, Secret>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more