compact_argon2
The ergonomics of the argon2 crate sucks.
This crate provides a thin wrapper around argon2's methods and an alternate,
much smaller binary serialization format. It uses whatever the default
parameters of argon2 current are, but uses deserialized parameters during
verification, just like the argon2 crate. It's hardcoded to use the
argon2id algorithm with the default salt and output lengths because get real.
Usage
let password = b"hunter2";
// hash a password
let hash = hash.unwrap;
// verify a password against a hash
assert!;
// can also be written as
assert!;
// serialize a hash into a byte array
let bytes: = hash.to_bytes;
// deserialize a hash from a byte array
let reconstructed = compact_argon2.from_bytes.unwrap;
assert_eq!;
Stability
The format may change with only a minor version bump until the 1.0.0 release, by which it should hopefully be stable.
serde compatibility
Enable the serde feature for Serialize and Deserialize impls on Hash.
Binary format
The Hash struct is fully stack allocated and serializes to a compact binary
representation. This is the recommended format, and the default for serde.
The format looks like this (made up types, all integers are big-endian):
base64 format
This crate also offers helpers to serialize/deserialize hashes in base64, if
you need to store hashes as strings for whatever reason. The output is still
constant size and always smaller than the PHC equivalent. This is just a
wrapper around the base64 crate with
the URL-safe alphabet and no padding (because it's constant size).
let hash = hash.unwrap;
let hash_string = hash.to_string;
let parsed_hash = hash_string.parse.unwrap;
assert_eq!;
// Can also be used with serde
sqlx::Postgres compatibility
Enable the postgres feature to use Hash with sqlx's PostgeSQL driver.
let mut user: User = query_as
.bind
.fetch_one
.await?;
let new_password = hash.unwrap;
query
.bind
.bind
.execute
.await?;