4 releases (breaking)
0.4.0 | Jun 25, 2023 |
---|---|
0.3.0 | Apr 24, 2022 |
0.2.0 | Apr 23, 2022 |
0.1.0 | Mar 9, 2022 |
#796 in Text processing
21 downloads per month
26KB
404 lines
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
Dependencies
~2.5MB
~57K SLoC