summaryrefslogtreecommitdiff
path: root/dhall/src/utils.rs
diff options
context:
space:
mode:
authorBasile Henry2020-11-03 23:32:51 +0100
committerBasile Henry2020-11-03 23:32:51 +0100
commita56cd6021705ebfd310bc902c4f549bea9b06a5b (patch)
tree8cd7429e654d31b9fbc68a97d71db92e7571c08a /dhall/src/utils.rs
parent559f64fd866fc74e930ddf8984fa11199a57ca2c (diff)
parentf87ffe7a590c9e0a3e0a57854c739a0f89c3784d (diff)
Merge remote-tracking branch 'upstream/master' into text-replace
Diffstat (limited to 'dhall/src/utils.rs')
-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())
+}