-- Lua-hashings @89879fe79b6f3dc495c607494126ec9c3912b8e9 | /hashings/crc32.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}c.digest_size=8;c.block_size=8;local function e(f)end;function c:new(g)if self~=c then return nil,"First argument must be self"end;local h=setmetatable({},d)h._crc=b(0xFFFFFFFF)if g~=nil then h:update(g)end;return h end;setmetatable(c,{__call=c.new})function c:copy()local h=c:new()h._crc=self._crc:copy()return h end;function c:update(g)local i;local j;if g==nil then g=""end;g=tostring(g)for k=1,#g do i=a.byte(g,k)self._crc=self._crc~i;for l=1,8 do j=self._crc&1*-1;self._crc=self._crc>>1~(0xEDB88320&j)end end end;function c:digest()return~self._crc:asbytestring()end;function c:hexdigest()local m;local n={}m=self:digest()for k=1,#m do n[k]=a.format("%02X",a.byte(m,k))end;return table.concat(n)end;return c
