Skip to main content

hash_from_slice

Function hash_from_slice 

Source
pub fn hash_from_slice(data: &[u8]) -> Result<String, SigmfError>
Expand description

Computes the SHA-512 digest of data.

This currently never fails; the Result is kept for consistency with the other hashing helpers.

ยงExamples

use sigmf::utils::hash::{hash_from_reader, hash_from_slice};

let digest = hash_from_slice(b"abc")?;
assert_eq!(digest.len(), 128);
assert!(digest.starts_with("ddaf35a193617aba"));

let mut reader = std::io::Cursor::new(b"abc".to_vec());
assert_eq!(hash_from_reader(&mut reader)?, digest);