l-sha.lua /size: 1085 b    last modification: 2020-07-01 14:35
1if not modules then modules = { } end modules ['l-sha'] = {
2    version   = 1.001,
3    comment   = "companion to luat-lib.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9if sha2 then
10
11    local lpegmatch    = lpeg.match
12    local lpegpatterns = lpeg.patterns
13    local bytestohex   = lpegpatterns.bytestohex
14    local bytestoHEX   = lpegpatterns.bytestoHEX
15
16    local digest256 = sha2.digest256
17    local digest384 = sha2.digest384
18    local digest512 = sha2.digest512
19
20    sha2.hash256 = function(str) return lpegmatch(bytestohex,digest256(str)) end
21    sha2.hash384 = function(str) return lpegmatch(bytestohex,digest384(str)) end
22    sha2.hash512 = function(str) return lpegmatch(bytestohex,digest512(str)) end
23    sha2.HASH256 = function(str) return lpegmatch(bytestoHEX,digest256(str)) end
24    sha2.HASH384 = function(str) return lpegmatch(bytestoHEX,digest384(str)) end
25    sha2.HASH512 = function(str) return lpegmatch(bytestoHEX,digest512(str)) end
26
27end
28