aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_cryptobox.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-18 09:26:59 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-18 09:26:59 +0000
commit567ecaebd920e7734239d1abd4b0a55521bf0e5c (patch)
tree4dc02fdd95efbde07fc41722ab6316033ec4432c /src/lua/lua_cryptobox.c
parentd99379d74590ba99fb0ad18e7d484046ef452ca4 (diff)
downloadrspamd-567ecaebd920e7734239d1abd4b0a55521bf0e5c.tar.gz
rspamd-567ecaebd920e7734239d1abd4b0a55521bf0e5c.zip
[Fix] Fix hash creation
Diffstat (limited to 'src/lua/lua_cryptobox.c')
-rw-r--r--src/lua/lua_cryptobox.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c
index efda2b2a7..aa46b1e66 100644
--- a/src/lua/lua_cryptobox.c
+++ b/src/lua/lua_cryptobox.c
@@ -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");