summaryrefslogtreecommitdiff
path: root/dhall/src/utils.rs
diff options
context:
space:
mode:
authorNadrieril2020-11-01 16:10:00 +0000
committerNadrieril2020-11-01 17:36:49 +0000
commit66ea301fc25a07485286560c434a9fdaf460c431 (patch)
treea0bc78be155be39e3da0ad5f61d7255057f8747a /dhall/src/utils.rs
parent2c245e7f5ce4019381e0fa47a1e2caf6276106be (diff)
Untangle caching code
Diffstat (limited to '')
-rw-r--r--dhall/src/utils.rs17
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())
+}