Closed boxbeam closed 11 months ago
The methods are part of the Digest
trait, which is implemented through the blanket impl for most of hashes in this repository. Also, the doctests are tested as part of our CI, so we know they are valid.
Might be good to mention that in the examples. I couldn't figure out why new() wasn't working and LSP didn't recommend the trait.
Which example are you looking at?
The one here says: https://github.com/RustCrypto/hashes#usage
sha2
and the other hash implementation crates re-export thedigest
crate and theDigest
trait for convenience, so you don't have to include it in yourCargo.toml
it as an explicit dependency.Now you can write the following code:
use sha2::{Sha256, Digest}; [...]
I guess to me it was unclear that new
comes from Digest
.
Maybe other trait imported caused your problem, if so, the code below should be helpful.
use sha2::{Digest, Sha256};
let mut hasher: Sha256 = Digest::new();
Digest::update(&mut hasher, b"hello");
let h = Digest::finalize(hasher);
Also worth noting:
finalize()
does not appear to exist