Sometimes the raw bytes of a hash are needed instead of the hexadecimal representation. For example for double-hashing.
Currently to achieve this I need to use the hex crate and call hex::decode(sha256::digest(...)).expect(...), which is an unnecessary layer of indirection.
The usual way to implement this is to have two separate methods, for example digest (yielding raw bytes) and hexdigest (yielding a string containing the hexadecimal representation).
Thanks to the Cargo.lock mechanism, backwards compatibility is not a technical issue and so the existing digest function could be renamed to hexdigest and another digest function added that yields &[u8] or [u8; 32].
But if you prefer the digest function to stay untouched for backwards compatibility, I suggest adding a function called for example digest_raw or digest_unencoded.
I'm willing to try making a PR but wanted to ask for your thoughts on this request beforehand.
Thank you for your effort!
Hello.
Sometimes the raw bytes of a hash are needed instead of the hexadecimal representation. For example for double-hashing. Currently to achieve this I need to use the
hex
crate and callhex::decode(sha256::digest(...)).expect(...)
, which is an unnecessary layer of indirection. The usual way to implement this is to have two separate methods, for exampledigest
(yielding raw bytes) andhexdigest
(yielding a string containing the hexadecimal representation).Thanks to the
Cargo.lock
mechanism, backwards compatibility is not a technical issue and so the existingdigest
function could be renamed tohexdigest
and anotherdigest
function added that yields&[u8]
or[u8; 32]
. But if you prefer thedigest
function to stay untouched for backwards compatibility, I suggest adding a function called for exampledigest_raw
ordigest_unencoded
.I'm willing to try making a PR but wanted to ask for your thoughts on this request beforehand. Thank you for your effort!