Module dryoc::generichash[][src]

Expand description

Generic hashing

GenericHash implements libsodium’s generic hashing, based on the Blake2b algorithm.

Rustaceous API example, one-time interface

use base64::encode;
use dryoc::generichash::{GenericHash, Key};

// NOTE: The type for `key` param must be specified, the compiler cannot infer it when
// we pass `None`.
let hash =
    GenericHash::hash_with_defaults_to_vec::<_, Key>(b"hello", None).expect("hash failed");

assert_eq!(
    encode(&hash),
    "Mk3PAn3UowqTLEQfNlol6GsXPe+kuOWJSCU0cbgbcs8="
);

Rustaceous API example, incremental interface

use base64::encode;
use dryoc::generichash::{GenericHash, Key};

// The compiler cannot infer the `Key` type, so we pass it below.
let mut hasher = GenericHash::new_with_defaults::<Key>(None).expect("new failed");
hasher.update(b"hello");
let hash = hasher.finalize_to_vec().expect("finalize failed");

assert_eq!(
    encode(&hash),
    "Mk3PAn3UowqTLEQfNlol6GsXPe+kuOWJSCU0cbgbcs8="
);

Re-exports

pub use crate::types::*;

Modules

protectednightly

Protected memory type aliases for GenericHash

Structs

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

Type Definitions

Stack-allocated hash output of the recommended output length.

Stack-allocated secret key for use with the generic hash algorithm.