]> git.e2factory.org Git - e2factory.git/commitdiff
hash: turn into proper module
authorGordon Hecker <gh@emlix.com>
Tue, 19 Jan 2010 17:21:56 +0000 (18:21 +0100)
committerGordon Hecker <gh@emlix.com>
Fri, 12 Feb 2010 09:51:58 +0000 (10:51 +0100)
Signed-off-by: Gordon Hecker <gh@emlix.com>
generic/hash.lua

index deb8d5645d1415af5f17962c1445791eed3e3e63..99d67435d59577a573711ce7ff13caf60ece8706 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
+module("hash", package.seeall)
 require("sha1")
 
 --- create a hash context
 -- @return a hash context object, or nil on error
 -- @return nil, an error string on error
-local function hash_start()
+function hash_start()
        local hc = {}
        for k,v in pairs(hash) do
                hc[k] = v
@@ -42,12 +43,12 @@ end
 --- add hash data
 -- @param hc the hash context
 -- @param data string: data
-local function hash_append(hc, data)
+function hash_append(hc, data)
        -- append the data
        hc.data = hc.data .. data
 end
 
-local function hash_line(hc, data)
+function hash_line(hc, data)
        hash_append(hc, data .. "\n")
 end
 
@@ -55,15 +56,9 @@ end
 -- @param hc the hash context
 -- @return the hash value, or nil on error
 -- @return an error string on error
-local function hash_finish(hc)
+function hash_finish(hc)
        local ctx = sha1.sha1_init()
        ctx:update(hc.data)
        hc.sha1 = string.lower(ctx:final())
        return hc.sha1
 end
-
-hash = {}
-hash.hash_start = hash_start
-hash.hash = hash_append
-hash.hash_line = hash_line
-hash.hash_finish = hash_finish