From 59153df919fc7e9da3c141675cdf79d2877e9ab2 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Mon, 6 Aug 2012 11:47:16 +0200 Subject: [PATCH] Unify indentation Signed-off-by: Tobias Ulmer --- generic/hash.lua | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/generic/hash.lua b/generic/hash.lua index 7201dc3..9b0a4ba 100644 --- a/generic/hash.lua +++ b/generic/hash.lua @@ -33,42 +33,42 @@ require("sha1") -- @return a hash context object, or nil on error -- @return nil, an error string on error function hash.hash_start() - local hc = {} + local hc = {} - for k,v in pairs(hash) do - hc[k] = v - end + for k,v in pairs(hash) do + hc[k] = v + end - hc.ctx = sha1.sha1_init() - hc.data = "" - hc.datalen = 0 + hc.ctx = sha1.sha1_init() + hc.data = "" + hc.datalen = 0 - return hc + return hc end --- add hash data -- @param hc the hash context -- @param data string: data function hash.hash_append(hc, data) - assert(type(hc) == "table" and type(hc.ctx) == "userdata") - assert(type(data) == "string") - - hc.data = hc.data .. data - hc.datalen = hc.datalen + string.len(data) - - -- Consume data and update hash whenever 64KB are available - if hc.datalen >= 64*1024 then - hc.ctx:update(hc.data) - hc.data = "" - hc.datalen = 0 - end + assert(type(hc) == "table" and type(hc.ctx) == "userdata") + assert(type(data) == "string") + + hc.data = hc.data .. data + hc.datalen = hc.datalen + string.len(data) + + -- Consume data and update hash whenever 64KB are available + if hc.datalen >= 64*1024 then + hc.ctx:update(hc.data) + hc.data = "" + hc.datalen = 0 + end end --- hash a line -- @param hc the hash context -- @param data string: data to hash, a newline is appended function hash.hash_line(hc, data) - hash.hash_append(hc, data .. "\n") + hash.hash_append(hc, data .. "\n") end --- hash a file @@ -77,27 +77,27 @@ end -- @return true on success, nil on error -- @return nil, error object on failure function hash.hash_file(hc, path) - assert(type(hc) == "table" and type(hc.ctx) == "userdata") - assert(type(path) == "string") + assert(type(hc) == "table" and type(hc.ctx) == "userdata") + assert(type(path) == "string") - local fd = io.open(path, "r") - if not fd then - return nil, new_error("could not open file '%s'", path) - end + local fd = io.open(path, "r") + if not fd then + return nil, new_error("could not open file '%s'", path) + end - local buf = "" - while true do - buf = fd:read(64*1024) - if buf == nil then - break - end + local buf = "" + while true do + buf = fd:read(64*1024) + if buf == nil then + break + end - hash.hash_append(hc, buf) - end + hash.hash_append(hc, buf) + end - fd:close() + fd:close() - return true + return true end --- add hash data @@ -105,19 +105,21 @@ end -- @return the hash value, or nil on error -- @return an error string on error function hash.hash_finish(hc) - assert(type(hc) == "table" and type(hc.ctx) == "userdata") + assert(type(hc) == "table" and type(hc.ctx) == "userdata") - hc.ctx:update(hc.data) + hc.ctx:update(hc.data) - local cs = string.lower(hc.ctx:final()) - assert(string.len(cs) == 40) + local cs = string.lower(hc.ctx:final()) + assert(string.len(cs) == 40) - -- Destroy the hash context to catch errors - for k,_ in pairs(hc) do - hc[k] = nil - end + -- Destroy the hash context to catch errors + for k,_ in pairs(hc) do + hc[k] = nil + end - return cs + return cs end return hash + +-- vim:sw=4:sts=4:et: -- 2.39.5