The HashRaw struct provides direct access to the individual components of an Argon2 hash. While the standard hash method on Hasher returns a string-encoded hash, you should use HashRaw if you need to programmatically inspect the raw bytes of the hash or the salt, or access the specific configuration parameters used (iterations, lanes, memory size, variant, and version).
You can obtain a HashRaw instance in two ways:
- Parsing a string: Use
.parse::<HashRaw>() on a standard string-encoded hash. - Directly from a Hasher: Call the
.hash_raw() method on a Hasher instance.
// Option 1: Parsing from a string
let hash_str = "$argon2id$v=19$m=4096,t=2,p=1$c29tZXNhbHQ$R09..."
let hash_raw: HashRaw = hash_str.parse().expect("Failed to parse hash");
// Accessing components
let salt = hash_raw.raw_salt_bytes();
let hash_bytes = hash_raw.raw_hash_bytes();
let iterations = hash_raw.iterations();
// Option 2: Obtaining directly from a Hasher
// (Assuming a Hasher instance exists)
let hash_raw = hasher.hash_raw();