From b46557938eb058b08e9abacacf9f5a19f07f0f6a Mon Sep 17 00:00:00 2001 From: Soojin Nam Date: Fri, 25 Mar 2016 11:54:13 +0900 Subject: [PATCH 1/3] add len parameter in update() of resty.md5 --- lib/resty/md5.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/resty/md5.lua b/lib/resty/md5.lua index 25d8393..85b8ab0 100644 --- a/lib/resty/md5.lua +++ b/lib/resty/md5.lua @@ -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 From d1348618308ccd54d62a7f5bd13a9460960960fb Mon Sep 17 00:00:00 2001 From: Soojin Nam Date: Mon, 28 Mar 2016 09:46:31 +0900 Subject: [PATCH 2/3] add test case update() with len param of md5 --- t/md5.t | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/md5.t b/t/md5.t index e5decfe..dc4491d 100644 --- a/t/md5.t +++ b/t/md5.t @@ -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] + From 53236a525037beef118d661a3c7d265327b1525e Mon Sep 17 00:00:00 2001 From: Soojin Nam Date: Mon, 28 Mar 2016 14:09:31 +0900 Subject: [PATCH 3/3] sample code for md5:update() with an optional len parameter --- README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 859a666..6790f37 100644 --- a/README.markdown +++ b/README.markdown @@ -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