dispnet-hash

Crates.iodispnet-hash
lib.rsdispnet-hash
version0.4.0
sourcesrc
created_at2022-03-09 19:14:41.583102
updated_at2023-06-25 16:20:24.551407
descriptionHash Library used for Dispnet
homepagehttps://github.com/Chtau/dispnet-hash
repositoryhttps://github.com/Chtau/dispnet-hash
max_upload_size
id547123
size32,510
Christoph Taucher (Chtau)

documentation

README

Dispnet Hash

Dispnet Hash produces a self descripting hash for easy backwards compatibility. The hash format follows the TLV (type-length-value) pattern.

  • First 2 characters are the hash type as integer with a leading 0 (Default is 01 which is Blake3 hash).
  • Then come 4 characters as integer with leading 0 which is the length of the bytes from the digest.
  • Digest value as hex.

Supported hash algorithm

Abstract hash structur

<type><bytes-length><value>

Hash value structur

01     0032           4878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215
02     0010           32323538363632303830
03     0084           246172676f6e326924763d3139246d3d343039362c743d332c703d31244d54497a4e4455324e7a6724686f56354d494638596a39746b39356c467365546279554a6e393336484944586754685533637065643151
Type | Bytes length | Hash

Usage

Create a hash

let dispnet_hash = DispnetHash::new("test".as_bytes());
let display_hash = format!("{}", dispnet_hash);
assert_eq!(display_hash, "0100324878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215");

Create a hash with hash type

let dispnet_hash = DispnetHash::create(HashType::CRC, "test".as_bytes(), None);
let display_hash = format!("{}", dispnet_hash);
assert_eq!(display_hash, "02001032323538363632303830");

Get hash parts

let dispnet_hash = "0100324878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215".parse::<DispnetHash>().unwrap();
assert_eq!(dispnet_hash.hash_type, HashType::Blake3);
assert_eq!(dispnet_hash.digest_length, 32);
assert_eq!(dispnet_hash.digest_value.len(), 32);

Verify Argon2 hash with value

assert!(DispnetHash::verify("030084246172676f6e326924763d3139246d3d343039362c743d332c703d31244d54497a4e4455324e7a6724686f56354d494638596a39746b39356c467365546279554a6e393336484944586754685533637065643151", "test".as_bytes()));

Build instruction

1.) Install Rust

2.) Build

cargo build

.) Test

cargo test

.) Benchmark

cargo bench

View Html report in target/criterion/report/index.html

Created with Criterion.rs

.) Publish

cargo publish --dry-run

Made by Christoph Taucher

License MIT

Commit count: 26

cargo fmt