Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Synopsis
ngx.say("failed to add data")
return
end

ok = md5:update("lo")
-- md5:update() with an optional "len" parameter
ok = md5:update("loxxx", 2)
if not ok then
ngx.say("failed to add data")
return
Expand Down
4 changes: 2 additions & 2 deletions lib/resty/md5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function _M.new(self)
end


function _M.update(self, s)
return C.MD5_Update(self._ctx, s, #s) == 1
function _M.update(self, s, len)
return C.MD5_Update(self._ctx, s, len or #s) == 1
end


Expand Down
33 changes: 33 additions & 0 deletions t/md5.t
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,36 @@ md5: d41d8cd98f00b204e9800998ecf8427e
--- no_error_log
[error]



=== TEST 4: MD5 update with len parameter
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local resty_md5 = require "resty.md5"
local str = require "resty.string"
local md5 = resty_md5:new()
ngx.say(md5:update("hello", 3))
local digest = md5:final()
ngx.say(digest == ngx.md5_bin("hel"))
md5 = resty_md5:new()
ngx.say(md5:update("hello", 3))
ngx.say(md5:update("loxxx", 2))
digest = md5:final()
ngx.say(digest == ngx.md5_bin("hello"))
ngx.say("md5: ", str.to_hex(digest))
';
}
--- request
GET /t
--- response_body
true
true
true
true
true
md5: 5d41402abc4b2a76b9719d911017c592
--- no_error_log
[error]