-- Lua-hashings @89879fe79b6f3dc495c607494126ec9c3912b8e9 | /hashings/adler32.lua | https://github.com/user-none/lua-hashings | License: MIT License | Minified using https://www.npmjs.com/package/luamin/v/1.0.4
-- Copyright (c) 2016 John Schember
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local a=require("string")local b=require("nums.uintn").u32;local c={}local d={__metatable={},__index=c}local e=65521;c.digest_size=8;c.block_size=8;function c:new(f)if self~=c then return nil,"First argument must be self"end;local g=setmetatable({},d)g._b1=b(1)g._b2=b(0)if f~=nil then g:update(f)end;return g end;setmetatable(c,{__call=c.new})function c:copy()local g=c:new()g._b1=self._b1:copy()g._b2=self._b2:copy()return g end;function c:update(f)local h;if f==nil then f=""end;f=tostring(f)for i=1,#f do h=a.byte(f,i)self._b1=(self._b1+h)%e;self._b2=(self._b2+self._b1)%e end end;function c:digest()return(self._b2<<16|self._b1):asbytestring()end;function c:hexdigest()local j;local k={}j=self:digest()for i=1,#j do k[i]=a.format("%02X",a.byte(j,i))end;return table.concat(k)end;return c
