pub struct DispnetHash {
pub hash_type: HashType,
pub digest_length: usize,
pub digest_value: Vec<u8>,
pub digest_encoded: u64,
/* private fields */
}Expand description
Dispnet hash is as self descriping hash format.
§Display format is structured as followed:
- 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.
§Examles
fn new_hash() {
let dispnet_hash = dispnet_hash::DispnetHash::new("test".as_bytes());
let display_hash = format!("{}", dispnet_hash);
assert_eq!(display_hash, "010324878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215");
}Fields§
§hash_type: HashType§digest_length: usize§digest_value: Vec<u8>§digest_encoded: u64Implementations§
Source§impl DispnetHash
impl DispnetHash
Sourcepub fn create(
hash_type: HashType,
value: &[u8],
config: Option<HashConfig>,
) -> Self
pub fn create( hash_type: HashType, value: &[u8], config: Option<HashConfig>, ) -> Self
Create a new dispnet hash.
§Usage
use dispnet_hash::{DispnetHash, HashType, HashConfig};
fn create_hashes() {
let dispnet_hash_Balke3 = DispnetHash::create(HashType::Blake3, "test".as_bytes(), None);
let dispnet_hash_CRC = DispnetHash::create(HashType::CRC, "test".as_bytes(), None);
let dispnet_hash_Argon2 = DispnetHash::create(HashType::Argon2, "test".as_bytes(), None);
let dispnet_hash_Argon2_slat = DispnetHash::create(HashType::Argon2, "test".as_bytes(), Some(HashConfig { salt: Some(Box::new(b"12345678".to_vec())) }));
}Sourcepub fn verify(hash: &str, value: &[u8]) -> bool
pub fn verify(hash: &str, value: &[u8]) -> bool
Verify a dispnet hash string with raw value. The hash must be created with the Argon2 type
§Usage
use dispnet_hash::{DispnetHash, HashType};
fn verify_hash() {
let dispnet_hash = DispnetHash::create(HashType::Argon2, "test".as_bytes(), None);
DispnetHash::verify(&dispnet_hash.to_string(), "test".as_bytes());
}Sourcepub fn verify_instance(hash: &DispnetHash, value: &[u8]) -> bool
pub fn verify_instance(hash: &DispnetHash, value: &[u8]) -> bool
Verify a dispnet hash instance with raw value. The hash must be created with the Argon2 type
§Usage
use dispnet_hash::{DispnetHash, HashType};
fn verify_hash_instance() {
let dispnet_hash = DispnetHash::create(HashType::Argon2, "test".as_bytes(), None);
DispnetHash::verify_instance(&dispnet_hash, "test".as_bytes());
}Sourcepub fn hex_to_bytes(s: &str) -> Option<Vec<u8>>
pub fn hex_to_bytes(s: &str) -> Option<Vec<u8>>
Convert a hexadecimal string to a vector of bytes.
Returns None if the input string has an odd length which makes it an invalid hex string.
§Usage
use dispnet_hash::DispnetHash;
fn hex_to_bytes() {
let hex_string = "74657374";
let bytes = DispnetHash::hex_to_bytes(hex_string).unwrap();
assert_eq!(bytes, vec![116, 101, 115, 116]);
}Sourcepub fn bytes_to_hex(bytes: &[u8]) -> String
pub fn bytes_to_hex(bytes: &[u8]) -> String
Convert a slice of bytes to a hexadecimal string.
§Usage
use dispnet_hash::DispnetHash;
fn bytes_to_hex() {
let bytes = vec![116, 101, 115, 116];
let hex_string = DispnetHash::bytes_to_hex(&bytes);
assert_eq!(hex_string, "74657374");
}Sourcepub fn encoded_u64(bytes: &[u8]) -> u64
pub fn encoded_u64(bytes: &[u8]) -> u64
Convert a slice of bytes to a u64 integer. If the length of the slice is less than 8, it is converted to a u64 integer using little-endian byte order. Otherwise, the last 8 bytes of the slice are converted to a u64 integer using little-endian byte order.
§Usage
use dispnet_hash::DispnetHash;
fn encoded_u64() {
let bytes = vec![0, 0, 0, 0, 0, 0, 0, 1];
let encoded = DispnetHash::encoded_u64(&bytes);
assert_eq!(encoded, 72057594037927936);
}Trait Implementations§
Source§impl Debug for DispnetHash
impl Debug for DispnetHash
Source§impl Display for DispnetHash
impl Display for DispnetHash
Source§impl FromStr for DispnetHash
impl FromStr for DispnetHash
Source§impl PartialEq<String> for DispnetHash
impl PartialEq<String> for DispnetHash
Source§impl PartialEq for DispnetHash
impl PartialEq for DispnetHash
Auto Trait Implementations§
impl Freeze for DispnetHash
impl RefUnwindSafe for DispnetHash
impl Send for DispnetHash
impl Sync for DispnetHash
impl Unpin for DispnetHash
impl UnwindSafe for DispnetHash
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more