Struct dryoc::generichash::GenericHash [−][src]
pub struct GenericHash<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> { /* fields omitted */ }
Expand description
Provides a generic hash function implementation based on Blake2b. Compatible with libsodium’s generic hash.
Implementations
impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> GenericHash<KEY_LENGTH, OUTPUT_LENGTH>
impl<const KEY_LENGTH: usize, const OUTPUT_LENGTH: usize> GenericHash<KEY_LENGTH, OUTPUT_LENGTH>
Returns a new hasher instance, with key
.
Updates the hasher state from input
.
Computes and returns the final hash value.
Computes and returns the final hash value as a Vec
. Provided for
convenience.
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::encode;
use dryoc::generichash::{GenericHash, Hash};
let output: Hash =
GenericHash::hash(b"hello", Some(b"a very secret key")).expect("hash failed");
assert_eq!(
encode(&output),
"AECDe+XJsB6nOkbCsbS/OPXdzpcRm3AolW/Bg1LFY9A="
);
Returns an instance of GenericHash
with the default output and key
length parameters.
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>
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.