fingerprint-struct
This crate allows for the computation of cryptographic hashes or arbitrary data structures.
It provides a Fingerprint trait which represents a type whose hash can be computed. It's implemented by default for most common types from std, such as primitives like u32 or bool, collections like Vec or BTreeSet, pointers like Box or Rc or specialized types like IpAddress. It also provides a derive macro which generates a Fingerprint implementation for any struct or enum.
It relies on traits from the digest crate, which means its compatible with all hash implementations from the Rust Crypto project.
Hashes are considered stable, changes to how a given data structure is hashed will cause a minor version bump. Note that making a change to your own type definitions might introduce hash collisions. To avoid this, you can include a version number in your data structures.
Instalation
Add the following lines to Cargo.toml:
[]
= "0.1.0"
or run:
Examples
Hashing a string
use Blake2b512;
use fingerprint;
use ToHex;
let hash = ;
let hash: String = hash.encode_hex_upper;
println!;
Hashing a custom data structure
use Blake2b512;
use ;
use ToHex;
let book = default;
let hash = ;
let hash: String = hash.encode_hex_upper;
println!;
no_std support
This crate supports no_std environments. Simply disable the default std feature:
[]
= { = "0.1.0", = false, = ["derive"] }
You can also optionally enable the alloc feature on targets that don't support std but support alloc:
[]
= { = "0.1.0", = false, = ["alloc", "derive"] }