# HG changeset patch # User Matthew Wild # Date 1679597653 0 # Node ID 5e2978489c95b039fa89747c6daa48a33507e179 # Parent 33d566513eb0088e84c9ed8414f0dfdcab0d51d3 libs/hashes: Support for luaossl (lua-luaossl on Debian) diff -r 33d566513eb0 -r 5e2978489c95 libs/hashes.lua --- 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;