From: Tobias Ulmer Date: Fri, 3 Aug 2012 14:45:27 +0000 (+0200) Subject: Change hash module to a more protected type X-Git-Tag: e2factory-2.3.13rc1~213 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=b4adb20045fa4b8a8880a7d127cbbc280b14ad72;p=e2factory.git Change hash module to a more protected type Signed-off-by: Tobias Ulmer --- diff --git a/generic/hash.lua b/generic/hash.lua index 95e8f15..7201dc3 100644 --- a/generic/hash.lua +++ b/generic/hash.lua @@ -1,6 +1,7 @@ --[[ e2factory, the emlix embedded build system + Copyright (C) 2012 Tobias Ulmer , emlix GmbH Copyright (C) 2007-2009 Gordon Hecker , emlix GmbH Copyright (C) 2007-2009 Oskar Schirmer , emlix GmbH Copyright (C) 2007-2008 Felix Winkelmann, emlix GmbH @@ -25,13 +26,13 @@ along with this program. If not, see . ]] -module("hash", package.seeall) +local hash = {} require("sha1") --- create a hash context -- @return a hash context object, or nil on error -- @return nil, an error string on error -function hash_start() +function hash.hash_start() local hc = {} for k,v in pairs(hash) do @@ -48,7 +49,7 @@ end --- add hash data -- @param hc the hash context -- @param data string: data -function hash_append(hc, data) +function hash.hash_append(hc, data) assert(type(hc) == "table" and type(hc.ctx) == "userdata") assert(type(data) == "string") @@ -66,8 +67,8 @@ end --- hash a line -- @param hc the hash context -- @param data string: data to hash, a newline is appended -function hash_line(hc, data) - hash_append(hc, data .. "\n") +function hash.hash_line(hc, data) + hash.hash_append(hc, data .. "\n") end --- hash a file @@ -75,7 +76,7 @@ end -- @param path string: the full path to the file -- @return true on success, nil on error -- @return nil, error object on failure -function hash_file(hc, path) +function hash.hash_file(hc, path) assert(type(hc) == "table" and type(hc.ctx) == "userdata") assert(type(path) == "string") @@ -91,7 +92,7 @@ function hash_file(hc, path) break end - hash_append(hc, buf) + hash.hash_append(hc, buf) end fd:close() @@ -103,7 +104,7 @@ end -- @param hc the hash context -- @return the hash value, or nil on error -- @return an error string on error -function hash_finish(hc) +function hash.hash_finish(hc) assert(type(hc) == "table" and type(hc.ctx) == "userdata") hc.ctx:update(hc.data) @@ -118,3 +119,5 @@ function hash_finish(hc) return cs end + +return hash diff --git a/local/e2tool.lua b/local/e2tool.lua index 70b79e4..51320fb 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -45,7 +45,7 @@ require("tools") require("environment") require("plugin") require("url") -require("hash") +local hash = require("hash") require("lock") require("e2util") require("e2option") diff --git a/local/files.lua b/local/files.lua index f232365..edede20 100644 --- a/local/files.lua +++ b/local/files.lua @@ -31,6 +31,7 @@ module("files", package.seeall) require("scm") +local hash = require("hash") --- validate source configuration, log errors to the debug log -- @param info the info table diff --git a/local/git.lua b/local/git.lua index f8b5a18..dda7c23 100644 --- a/local/git.lua +++ b/local/git.lua @@ -31,6 +31,7 @@ module("git", package.seeall) require("scm") +local hash = require("hash") --- git branch wrapper -- get the current branch diff --git a/local/svn.lua b/local/svn.lua index 78baf83..31bd3f3 100644 --- a/local/svn.lua +++ b/local/svn.lua @@ -29,6 +29,7 @@ module("svn", package.seeall) require("scm") +local hash = require("hash") --- translate url into subversion url -- @param u table: url table