feat: add util::digest_sha256

This commit is contained in:
2020-08-02 00:54:15 +08:00
parent 71ae5e2eb2
commit 67b8311400
4 changed files with 82 additions and 0 deletions

12
src/util.rs Normal file
View File

@@ -0,0 +1,12 @@
use sha2::{ Digest, Sha256 };
pub fn digest_sha256(bs: &[u8]) -> Vec<u8> {
let mut sha256 = Sha256::new();
sha256.update(bs);
sha256.finalize().to_vec()
}
#[test]
fn test_digest_sha256() {
assert_eq!(hex::decode("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9").unwrap(), digest_sha256(b"hello world"));
}