]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix hash creation
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Nov 2016 09:26:59 +0000 (09:26 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Nov 2016 09:26:59 +0000 (09:26 +0000)
src/lua/lua_cryptobox.c

index efda2b2a7749e8653f89aa358e3d2ad8ad3bceb0..aa46b1e66b4e209a36e97ffa9f7a6ae089f2dacc 100644 (file)
@@ -682,14 +682,11 @@ lua_cryptobox_hash_create (lua_State *L)
        gsize len = 0;
 
        h = rspamd_lua_hash_create (NULL);
-       ph = lua_newuserdata (L, sizeof (void *));
-       *ph = h;
-       rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1);
 
        if (lua_type (L, 1) == LUA_TSTRING) {
                s = lua_tolstring (L, 1, &len);
        }
-       else if (lua_isuserdata (L, 1)) {
+       else if (lua_type (L, 1) == LUA_TUSERDATA) {
                t = lua_check_text (L, 1);
 
                if (!t) {
@@ -704,6 +701,10 @@ lua_cryptobox_hash_create (lua_State *L)
                rspamd_lua_hash_update (h, s, len);
        }
 
+       ph = lua_newuserdata (L, sizeof (void *));
+       *ph = h;
+       rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1);
+
        return 1;
 }
 
@@ -727,14 +728,11 @@ lua_cryptobox_hash_create_specific (lua_State *L)
        }
 
        h = rspamd_lua_hash_create (type);
-       ph = lua_newuserdata (L, sizeof (void *));
-       *ph = h;
-       rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1);
 
        if (lua_type (L, 2) == LUA_TSTRING) {
                s = lua_tolstring (L, 2, &len);
        }
-       else if (lua_isuserdata (L, 2)) {
+       else if (lua_type (L, 2) == LUA_TUSERDATA) {
                t = lua_check_text (L, 2);
 
                if (!t) {
@@ -749,6 +747,10 @@ lua_cryptobox_hash_create_specific (lua_State *L)
                rspamd_lua_hash_update (h, s, len);
        }
 
+       ph = lua_newuserdata (L, sizeof (void *));
+       *ph = h;
+       rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1);
+
        return 1;
 }
 
@@ -772,14 +774,11 @@ lua_cryptobox_hash_create_keyed (lua_State *L)
        if (key != NULL) {
                h = rspamd_lua_hash_create (NULL);
                rspamd_cryptobox_hash_init (h->h, key, keylen);
-               ph = lua_newuserdata (L, sizeof (void *));
-               *ph = h;
-               rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1);
 
                if (lua_type (L, 2) == LUA_TSTRING) {
                        s = lua_tolstring (L, 2, &len);
                }
-               else if (lua_isuserdata (L, 2)) {
+               else if (lua_type (L, 2) == LUA_TUSERDATA) {
                        t = lua_check_text (L, 2);
 
                        if (!t) {
@@ -793,6 +792,10 @@ lua_cryptobox_hash_create_keyed (lua_State *L)
                if (s) {
                        rspamd_cryptobox_hash_update (h, s, len);
                }
+
+               ph = lua_newuserdata (L, sizeof (void *));
+               *ph = h;
+               rspamd_lua_setclass (L, "rspamd{cryptobox_hash}", -1);
        }
        else {
                return luaL_error (L, "invalid arguments");