Software /
code /
verse
Diff
libs/hashes.lua @ 484:5e2978489c95
libs/hashes: Support for luaossl (lua-luaossl on Debian)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 23 Mar 2023 18:54:13 +0000 |
parent | 443:89526c890363 |
line wrap: on
line diff
--- a/libs/hashes.lua Fri Mar 17 17:09:00 2023 +0000 +++ b/libs/hashes.lua Thu Mar 23 18:54:13 2023 +0000 @@ -10,6 +10,12 @@ if ok then f(pkg); end end +local function to_hex(data) + return (data:gsub(".", function (c) + return ("%02x"):format(c:byte()); + end)); +end + with("util.sha1", function (sha1) _M.sha1 = sha1.sha1; end); @@ -45,4 +51,17 @@ end; end); +with("openssl.digest", function (digest) + local function make_digest_func(digest_name) + return function (data, hex) + local d = digest.new(digest_name):final(data); + if hex then + return to_hex(d); + end + return d; + end; + end + _M.sha1 = make_digest_func("sha1"); +end); + return _M;