]> git.e2factory.org Git - e2factory.git/commitdiff
remove lsha1 and adjust hash module to lsha
authorTobias Ulmer <tu@emlix.com>
Thu, 1 Dec 2016 15:04:26 +0000 (16:04 +0100)
committerTobias Ulmer <tu@emlix.com>
Thu, 1 Dec 2016 15:04:26 +0000 (16:04 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/Makefile
generic/hash.lua
generic/lsha1.c [deleted file]

index d6a5e64068c8b56a14cdcdec1ff91ee31fd25717..dde3a453b023264eb7bef400799d908b13a0248f 100644 (file)
@@ -23,7 +23,7 @@ LUA_LIBS = strict.lua plugin.lua e2lib.lua console.lua class.lua
 LUA_LIBS += e2option.lua hash.lua tools.lua transport.lua cache.lua url.lua
 LUA_LIBS += generic_git.lua eio.lua err.lua lock.lua errno.lua trace.lua
 LUA_LIBS += assrt.lua
-SO_LIBS = lsha1.so lsha.so leio.so le2lib.so
+SO_LIBS = lsha.so leio.so le2lib.so
 
 CLEAN_FILES = *~ *.o *.so
 
@@ -32,8 +32,6 @@ CLEAN_FILES = *~ *.o *.so
 
 all: $(SO_LIBS)
 
-lsha1.so: lsha1.o sha1.o
-
 lsha.so: lsha.o sha1.o sha2.o
 
 sha2.o: sha2.c sha2.h
index 078565ca9c6fe7dbfea3b0fa28dd9a81bcd5b270..f9a32340ec0ff8fbba1d5d6a10b20bf07512a349 100644 (file)
@@ -22,7 +22,7 @@ local hash = {}
 local e2lib = require("e2lib")
 local eio = require("eio")
 local err = require("err")
-local lsha1 = require("lsha1")
+local lsha = require("lsha")
 local strict = require("strict")
 local trace = require("trace")
 
@@ -162,14 +162,8 @@ end
 --- Create a hash context. Throws error object on failure.
 -- @return Hash context object.
 function hash.hash_start()
-    local errstring, hc
-    hc = { _data = "" }
-
-    hc._ctx, errstring = lsha1.init()
-    if not hc._ctx then
-        error(err.new("initializing SHA1 context failed: %s", errstring))
-    end
-
+    local hc = { _data = "" }
+    hc._ctx = lsha.sha1_init()
     return strict.lock(hc)
 end
 
@@ -180,16 +174,12 @@ function hash.hash_append(hc, data)
     assert(type(hc) == "table")
     assert(type(data) == "string")
     assert(hc._data and hc._ctx)
-    local rc, errstring
 
     hc._data = hc._data .. data
 
     -- Consume data and update hash whenever 64KB are available
-    if #hc._data >= 64*1024 then
-        rc, errstring = lsha1.update(hc._ctx, hc._data)
-        if not rc then
-            error(err.new("%s", errstring))
-        end
+    if #hc._data >= 65536 then
+        lsha.sha1_update(hc._ctx, hc._data)
         hc._data = ""
     end
 end
@@ -348,11 +338,7 @@ function hash.hash_file_once(path)
         return false, re
     end
 
-    cs, re = hash.hash_finish(hc)
-    if not cs then
-        return false, re
-    end
-
+    cs = hash.hash_finish(hc)
     hcache_add(path, cs)
     return cs
 end
@@ -361,22 +347,14 @@ end
 -- @param hc the hash context
 -- @return SHA1 Checksum.
 function hash.hash_finish(hc)
-    local rc, errstring, cs
-
-    rc, errstring = lsha1.update(hc._ctx, hc._data)
-    if not rc then
-        error(err.new("%s", errstring))
-    end
+    local cs
 
-    cs, errstring = lsha1.final(hc._ctx)
-    if not cs then
-        error(err.new("%s", errstring))
-    end
+    lsha.sha1_update(hc._ctx, hc._data)
+    cs = lsha.sha1_final(hc._ctx)
 
     -- Destroy the hash context to catch errors
-    for k,_ in pairs(hc) do
-        hc[k] = nil
-    end
+    hc._data = nil
+    hc._ctx = nil
 
     return cs
 end
diff --git a/generic/lsha1.c b/generic/lsha1.c
deleted file mode 100644 (file)
index 25e45e2..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2007-2016 emlix GmbH, see file AUTHORS
- *
- * This file is part of e2factory, the emlix embedded build system.
- * For more information see http://www.e2factory.org
- *
- * e2factory is a registered trademark of emlix GmbH.
- *
- * e2factory is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "lua.h"
-#include "lualib.h"
-#include "lauxlib.h"
-
-#include "sha1.h"
-
-static int
-init(lua_State *L)
-{
-       SHA1_CTX *ctx = malloc(sizeof(SHA1_CTX));
-       if (ctx == NULL) {
-               lua_pushboolean(L, 0);
-               lua_pushstring(L, strerror(errno));
-               return 2;
-       }
-
-       SHA1Init(ctx);
-       lua_pushlightuserdata(L, ctx);
-       return 1;
-}
-
-static int
-update(lua_State *L)
-{
-       const char *s;
-       size_t len;
-       SHA1_CTX *ctx;
-
-       ctx = lua_touserdata(L, 1);
-       if (ctx == NULL) {
-               lua_pushboolean(L, 0);
-               lua_pushstring(L, "lsha1.update: missing sha1 context");
-               return 2;
-       }
-
-       s = lua_tolstring(L, 2, &len);
-       if (s == NULL) {
-               lua_pushboolean(L, 0);
-               lua_pushstring(L, "lsha1.update: data missing or of wrong type");
-               return 2;
-       }
-
-       SHA1Update(ctx, (unsigned char *)s, len);
-       lua_pushboolean(L, 1);
-
-       return 1;
-}
-
-static int
-final(lua_State *L)
-{
-       SHA1_CTX *ctx;
-       unsigned char digest[20];
-       char s[41];
-       int i;
-
-       ctx = lua_touserdata(L, 1);
-       if (ctx == NULL) {
-               lua_pushboolean(L, 0);
-               lua_pushstring(L, "lsha1.final: missing sha1 context");
-               return 2;
-       }
-
-       SHA1Final(digest, ctx);
-
-       memset(ctx, 0, sizeof(SHA1_CTX));
-       free(ctx);
-
-       for (i = 0; i < 20; i++) {
-               snprintf(s + i*2, 2+1,  "%02x", digest[i]);
-       }
-       lua_pushstring(L, s);
-
-       return 1;
-}
-
-static luaL_reg lib[] = {
-       { "init",       init },
-       { "update",     update },
-       { "final",      final },
-       { NULL,         NULL }
-};
-
-int luaopen_lsha1(lua_State *L)
-{
-       luaL_Reg *next;
-
-       lua_newtable(L);
-       for (next = lib; next->name != NULL; next++) {
-               lua_pushcfunction(L, next->func);
-               lua_setfield(L, -2, next->name);
-       }
-
-       return 1;
-}