Trait Hasher

Source
pub trait Hasher: 'static {
    type Config: Send + Sync + 'static;
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn hash(
        data: impl AsRef<[u8]>,
        config: &Self::Config,
    ) -> Result<String, Self::Error>;
    fn verify(data: impl AsRef<[u8]>, hash: &str) -> Result<bool, Self::Error>;
}
Expand description

Implement this to use your own hashing algorithm with this library

Required Associated Types§

Source

type Config: Send + Sync + 'static

The Config type for your hash algorithm

Source

type Error: Error + Send + Sync + 'static

This is the Error you return from your hash library

Required Methods§

Source

fn hash( data: impl AsRef<[u8]>, config: &Self::Config, ) -> Result<String, Self::Error>

Use your hasher to create a hash from the password (data) and a Config instance.

Source

fn verify(data: impl AsRef<[u8]>, hash: &str) -> Result<bool, Self::Error>

Verify whether the password (data) and hash match.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Hasher for Argon2id

Available on crate feature rust-argon2 only.
Source§

impl Hasher for Bcrypt

Available on crate feature bcrypt only.