RustCrypto / hashes

Collection of cryptographic hash functions written in pure Rust
1.75k stars 238 forks source link

Point users to how to make hex strings #589

Closed ChrisJefferson closed 2 weeks ago

ChrisJefferson commented 1 month ago

I want to get hashes in "that standard hex string format", which most hashes are displayed in all over the internet and I found this a bit harder than I expected. I realise it's obvious once you know, but we all didn't know once!

After some testing, it seems what I want is the 'base16ct' crate. Would you be open to a change to the readme which removed the base64ct example, and just gave base16ct? Maybe, something like (I'll go do this properly / clean up if the idea seems reasonable):

Hash functions are usually displayed to users as hex strings. You can do this with the base16ct crate:

There are a number of other ways to display hashes, including `base64ct`, which can be seen in the `formats` repository (which links to https://github.com/RustCrypto/formats/)
newpavlov commented 2 weeks ago

The repository readme already contains this example:

use base64ct::{Base64, Encoding};

let base64_hash = Base64::encode_string(&hash);
println!("Base64-encoded hash: {}", base64_hash);

let hex_hash = base16ct::lower::encode_string(&hash);
println!("Hex-encoded hash: {}", hex_hash);

I guess we could add hex-encoding examples to all crate docs. It would require adding base16ct to dev dependencies for all crates, but it should be fine.