pub struct GenericHash<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> { /* private fields */ }
Expand description

Provides a generic hash function implementation based on Blake2b. Compatible with libsodium’s generic hash.

Implementations§

source§

impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> GenericHash<KEY_LENGTH, OUTPUT_LENGTH>

source

pub fn new<Key: ByteArray<KEY_LENGTH>>(key: Option<&Key>) -> Result<Self, Error>

Returns a new hasher instance, with key.

source

pub fn update<Input: Bytes + ?Sized>(&mut self, input: &Input)

Updates the hasher state from input.

source

pub fn finalize<Output: NewByteArray<OUTPUT_LENGTH>>( self ) -> Result<Output, Error>

Computes and returns the final hash value.

source

pub fn finalize_to_vec(self) -> Result<Vec<u8>, Error>

Computes and returns the final hash value as a Vec. Provided for convenience.

source

pub fn hash<Input: Bytes + ?Sized, Key: ByteArray<KEY_LENGTH>, Output: NewByteArray<OUTPUT_LENGTH>>( input: &Input, key: Option<&Key> ) -> Result<Output, Error>

Onet-time interface for the generic hash function. Computes the hash for input with optional key. The output length is determined by the type signature of Output.

Example
use base64::engine::general_purpose;
use base64::Engine as _;
use dryoc::generichash::{GenericHash, Hash};

let output: Hash =
    GenericHash::hash(b"hello", Some(b"a very secret key")).expect("hash failed");

assert_eq!(
    general_purpose::STANDARD.encode(&output),
    "AECDe+XJsB6nOkbCsbS/OPXdzpcRm3AolW/Bg1LFY9A="
);
source

pub fn hash_to_vec<Input: Bytes, Key: ByteArray<KEY_LENGTH>>( input: &Input, key: Option<&Key> ) -> Result<Vec<u8>, Error>

Convenience wrapper for GenericHash::hash.

source§

impl GenericHash<CRYPTO_GENERICHASH_KEYBYTES, CRYPTO_GENERICHASH_BYTES>

source

pub fn new_with_defaults<Key: ByteArray<CRYPTO_GENERICHASH_KEYBYTES>>( key: Option<&Key> ) -> Result<Self, Error>

Returns an instance of GenericHash with the default output and key length parameters.

source

pub fn hash_with_defaults<Input: Bytes + ?Sized, Key: ByteArray<CRYPTO_GENERICHASH_KEYBYTES>, Output: NewByteArray<CRYPTO_GENERICHASH_BYTES>>( input: &Input, key: Option<&Key> ) -> Result<Output, Error>

Hashes input using key, with the default length parameters. Provided for convenience.

source

pub fn hash_with_defaults_to_vec<Input: Bytes + ?Sized, Key: ByteArray<CRYPTO_GENERICHASH_KEYBYTES>>( input: &Input, key: Option<&Key> ) -> Result<Vec<u8>, Error>

Hashes input using key, with the default length parameters, returning a Vec. Provided for convenience.

Auto Trait Implementations§

§

impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> RefUnwindSafe for GenericHash<KEY_LENGTH, OUTPUT_LENGTH>

§

impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> Send for GenericHash<KEY_LENGTH, OUTPUT_LENGTH>

§

impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> Sync for GenericHash<KEY_LENGTH, OUTPUT_LENGTH>

§

impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> Unpin for GenericHash<KEY_LENGTH, OUTPUT_LENGTH>

§

impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> UnwindSafe for GenericHash<KEY_LENGTH, OUTPUT_LENGTH>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.