Browse Source

[Fix] Fix hash creation

tags/1.4.0
Vsevolod Stakhov 7 years ago
parent
commit
567ecaebd9
1 changed files with 15 additions and 12 deletions
  1. 15
    12
      src/lua/lua_cryptobox.c

+ 15
- 12
src/lua/lua_cryptobox.c View 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");

Loading…
Cancel
Save