dynhash 0.1.0

Dynamic trait-object hashing library
Documentation
  • Coverage
  • 16%
    8 out of 50 items documented1 out of 45 items with examples
  • Size
  • Source code size: 32.08 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.51 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lschuermann

Simple dynamic trait-object based hashing library

This library allows you to define a thin non-generic interface, over which you can pass various hashes and hash functions. This is done using Trait Objects.

While every crate can define and implement custom Hash / HashType structs, this library has built-in support for the

  • sha3
  • sha2

crates.

These can be enabled by the "sha2" or "sha3" features respectively.

Example

Let's suppose you're writing a web-server library that accepts a hash from a client. The hash and hash type are passed as a byte slice and &str respectively. The web-server shouldn't have any knowledge about the allowed hash types, these can be passed in at runtime:

use dynhash::{Hash, HashType};

fn new_hash(
    available_types: &[&'static HashType],
    digest: &[u8],
    hash_type: &str,
) -> Option<Box<Hash>> {
    for h in available_types.iter() {
        if h.as_string() == hash_type {
            return h.new_with_content(digest).ok();
        }
    }

    return None;
}

This allows the web-server library to support all kinds of hashes, that the higher-level crate chooses to support.