Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unencoded hash #22

Open
laerling opened this issue Mar 31, 2024 · 1 comment
Open

Add support for unencoded hash #22

laerling opened this issue Mar 31, 2024 · 1 comment

Comments

@laerling
Copy link
Contributor

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 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!

@baoyachi
Copy link
Owner

baoyachi commented Apr 1, 2024

@laerling Very good suggestion, looking forward to your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants