Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad argument #1 to 'nettle_md5_init' #13

Closed
xiangnanscu opened this issue Jul 22, 2017 · 11 comments
Closed

bad argument #1 to 'nettle_md5_init' #13

xiangnanscu opened this issue Jul 22, 2017 · 11 comments

Comments

@xiangnanscu
Copy link

Hello. latest openresty and lua-resty-nettle (via opm). when I test like this:

    location = /test {
        content_by_lua_block {
local require = require
local print = print
local gsub = string.gsub
local byte = string.byte
local format = string.format
local ipairs = ipairs
local concat = table.concat

local function hex(str,spacer)
    return (gsub(str,"(.)", function (c)
        return format("%02X%s", byte(c), spacer or "")
    end))
end
local md5 = require "resty.nettle.md5"
ngx.say("md5      ", #md5(""), hex(md5("")))
local hash = md5.new()
hash:update("")
ngx.say("md5      ", #hash:digest(), hex(hash:digest()))
        }
    }

error raised:

2017/07/22 18:29:01 [error] 26288#26288: *834 lua entry thread aborted: runtime error: /usr/local/openresty/site/lualib/resty/nettle/md5.lua:22: bad argument #1 to 'nettle_md5_init' (cannot convert 'struct MD5state_st [1]' to 'struct md5_ctx *')
stack traceback:
coroutine 0:
	[C]: in function 'nettle_md5_init'
	/usr/local/openresty/site/lualib/resty/nettle/md5.lua:22: in function 'md5'
	content_by_lua(dev.conf:45):16: in function <content_by_lua(dev.conf:45):1>, client: 127.0.0.1, server: , request: "GET /test HTTP/1.1", host: "xxx.cn:9000"
@xiangnanscu
Copy link
Author

Ubuntu server 14.04. When I run the code via luajit test.lua, no error. Seems only occur in OpenResty.

@xiangnanscu
Copy link
Author

xiangnanscu commented Jul 22, 2017

Find the reason, but don't know why.
if I use local resty_md5 = require "resty.md5" before requiring resty.nettle.md5, error occurs

@xiangnanscu
Copy link
Author

error:

local resty_md5 = require "resty.md5"
local md5 = require "resty.nettle.md5"

no error:

local md5 = require "resty.nettle.md5"
local resty_md5 = require "resty.md5"

@xiangnanscu
Copy link
Author

In the meantime, I've also found that I need to preload resty.nettle.md5 in the init_by_lua* phrase, otherwise (such as first load it when request comes)the error would raise.

@bungle
Copy link
Owner

bungle commented Jul 23, 2017

They are two different libraries, and different interfaces.

resty.md5 comes from here (and uses OpenSSL):
https://github.com/openresty/lua-resty-string/blob/master/lib/resty/md5.lua

resty.nettle.md5 is the Nettle binding (and uses Nettle, obviously), and comes from here:
https://github.com/bungle/lua-resty-nettle/blob/master/lib/resty/nettle/md5.lua

@xiangnanscu
Copy link
Author

@bungle hello, sorry, I don't quite get it. I know they are different, does that means I shouldn't use them together?

@bungle
Copy link
Owner

bungle commented Jul 23, 2017

Can you provide a minimal example where the error occurs?

@xiangnanscu
Copy link
Author

@bungle run mkdir logs tmp && nginx -p . -c nginx.conf

worker_processes  1;
user root root;

events {worker_connections  1024;}

http {

    access_log  logs/access.log;
    error_log  logs/error.log;

    client_body_temp_path tmp/client_body_temp;
    fastcgi_temp_path tmp/fastcgi_temp;
    proxy_temp_path tmp/proxy_temp;
    scgi_temp_path tmp/scgi_temp;
    uwsgi_temp_path tmp/uwsgi_temp;
    

    
    server {
        listen       8888;
        
        location / {
            content_by_lua_block {

local require = require
local print = print
local gsub = string.gsub
local byte = string.byte
local format = string.format
local ipairs = ipairs
local concat = table.concat
local resty_md5 = require "resty.md5"
local md5 = require "resty.nettle.md5"

local function hex(str,spacer)
    return (gsub(str,"(.)", function (c)
        return format("%02X%s", byte(c), spacer or "")
    end))
end
ngx.say("md5      ", #md5(""), hex(md5("")))
local hash = md5.new()
hash:update("")
ngx.say("md5      ", #hash:digest(), hex(hash:digest()))

            }
        }
    
    
    }

    
}

@bungle
Copy link
Owner

bungle commented Jul 24, 2017

It looks like both define MD5_CTX.

@bungle
Copy link
Owner

bungle commented Jul 24, 2017

@xiangnanscu,

I will rename those in my lib so they will not cause problems. With C there is no namespaces so I have to prefix those. Same could be suggested to OpenResty as well. But I will do it for this lib.

@xiangnanscu
Copy link
Author

@bungle thank you, bungle. btw, lua-resty-nettle is very useful for me because hmacsha1 etc. Actually, if I must choose one, I'd choose yours. haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants