diff options
author | Nadrieril | 2020-11-01 18:50:09 +0000 |
---|---|---|
committer | GitHub | 2020-11-01 18:50:09 +0000 |
commit | 2ae979a22ee4b79590f74110d61164383c7b5182 (patch) | |
tree | 5286606d6d59f5d5d4b9ecb7f651c97d201a092e /dhall/src/utils.rs | |
parent | 48037367933085ca9c1c67c8c59f311e2b21be6d (diff) | |
parent | e5381c9b76f1d88dedb4a453cd026c8e98be5533 (diff) |
Merge pull request #192 from Nadrieril/rework-caching
Diffstat (limited to '')
-rw-r--r-- | dhall/src/utils.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/dhall/src/utils.rs b/dhall/src/utils.rs new file mode 100644 index 0000000..d1e642a --- /dev/null +++ b/dhall/src/utils.rs @@ -0,0 +1,17 @@ +use std::fs::File; +use std::io::Read; +use std::path::Path; + +use crate::error::Error; + +// Compute the sha256 hash of a bitstring. +pub fn sha256_hash(data: &[u8]) -> Box<[u8]> { + use sha2::Digest; + sha2::Sha256::digest(data).as_slice().into() +} + +pub fn read_binary_file(path: impl AsRef<Path>) -> Result<Box<[u8]>, Error> { + let mut buffer = Vec::new(); + File::open(path)?.read_to_end(&mut buffer)?; + Ok(buffer.into()) +} |