summaryrefslogtreecommitdiff
path: root/scripts/granger/util.lua
blob: 77dc4765e3a1f0219b10d8d15b12e8fb19263faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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