dhall/utils.rs
1use std::fs::File;
2use std::io::Read;
3use std::path::Path;
4
5use crate::error::Error;
6
7// Compute the sha256 hash of a bitstring.
8pub fn sha256_hash(data: &[u8]) -> Box<[u8]> {
9 use sha2::Digest;
10 sha2::Sha256::digest(data).as_slice().into()
11}
12
13pub fn read_binary_file(path: impl AsRef<Path>) -> Result<Box<[u8]>, Error> {
14 let mut buffer = Vec::new();
15 File::open(path)?.read_to_end(&mut buffer)?;
16 Ok(buffer.into())
17}