4 个版本 (破坏性更新)
0.4.0 | 2023 年 6 月 25 日 |
---|---|
0.3.0 | 2022 年 4 月 24 日 |
0.2.0 | 2022 年 4 月 23 日 |
0.1.0 | 2022 年 3 月 9 日 |
#677 in 文本处理
每月 21 次下载
26KB
404 代码行
Dispnet Hash
Dispnet Hash 生成自描述哈希,以便实现向后兼容性。哈希格式遵循 TLV (类型-长度-值) 模式。
- 前两个字符是哈希类型,以整数表示,前面有前导 0(默认是 01,表示 Blake3 哈希)。
- 然后是 4 个字符的整数,前面有前导 0,表示来自摘要的字节数。
- 十六进制摘要值。
支持的哈希算法
抽象哈希结构
<type><bytes-length><value>
哈希值结构
01 0032 4878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215
02 0010 32323538363632303830
03 0084 246172676f6e326924763d3139246d3d343039362c743d332c703d31244d54497a4e4455324e7a6724686f56354d494638596a39746b39356c467365546279554a6e393336484944586754685533637065643151
Type | Bytes length | Hash
用法
创建哈希
let dispnet_hash = DispnetHash::new("test".as_bytes());
let display_hash = format!("{}", dispnet_hash);
assert_eq!(display_hash, "0100324878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215");
创建具有哈希类型的哈希
let dispnet_hash = DispnetHash::create(HashType::CRC, "test".as_bytes(), None);
let display_hash = format!("{}", dispnet_hash);
assert_eq!(display_hash, "02001032323538363632303830");
获取哈希部分
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);
使用值验证 Argon2 哈希
assert!(DispnetHash::verify("030084246172676f6e326924763d3139246d3d343039362c743d332c703d31244d54497a4e4455324e7a6724686f56354d494638596a39746b39356c467365546279554a6e393336484944586754685533637065643151", "test".as_bytes()));
构建说明
1.) 安装 Rust
2.) 构建
cargo build
.) 测试
cargo test
.) 基准测试
cargo bench
在 target/criterion/report/index.html 中查看 Html 报告
使用 Criterion.rs 创建
.) 发布
cargo publish --dry-run
由 Christoph Taucher 制作
许可证 MIT
依赖项
~2MB
~52K SLoC