summaryrefslogtreecommitdiff
path: root/scripts/granger/util.lua
diff options
context:
space:
mode:
authorIronClawTrem <louie.nutman@gmail.com>2020-02-16 03:40:06 +0000
committerIronClawTrem <louie.nutman@gmail.com>2020-02-16 03:40:06 +0000
commit425decdf7e9284d15aa726e3ae96b9942fb0e3ea (patch)
tree6c0dd7edfefff1be7b9e75fe0b3a0a85fe1595f3 /scripts/granger/util.lua
parentccb0b2e4d6674a7a00c9bf491f08fc73b6898c54 (diff)
create tremded branch
Diffstat (limited to 'scripts/granger/util.lua')
-rw-r--r--scripts/granger/util.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/granger/util.lua b/scripts/granger/util.lua
new file mode 100644
index 0000000..77dc476
--- /dev/null
+++ b/scripts/granger/util.lua
@@ -0,0 +1,28 @@
+--
+-- util.lua
+-- various utility functions
+-- Copyright (c) 2016 Jeff Kent <jeff@jkent.net>
+--
+
+local function hash_file(file, ctx)
+ local f = io.open(file, "r")
+ if f == nil then
+ return nil
+ end
+ repeat
+ local buf = f:read(0x10000)
+ ctx:update(buf)
+ until buf == nil
+ f:close()
+ return tostring(ctx)
+end
+
+function sha256_file(file)
+ local ctx = nettle.sha256()
+ return hash_file(file, ctx)
+end
+
+function md5_file(file)
+ local ctx = nettle.md5()
+ return hash_file(file, ctx)
+end