summaryrefslogtreecommitdiff
path: root/scripts/granger/util.lua
diff options
context:
space:
mode:
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