Annotate

libs/hashes.lua @ 482:4c4f3dd62c54

squishy: Comment legacy protocol plugins by default
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Mar 2023 12:31:28 +0000
parent 443:89526c890363
child 484:5e2978489c95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
389
bf3a4fcdcb76 libs.hashes: Wrap LuaCrypto with fallback to util.sha1
Kim Alvefur <zash@zash.se>
parents: 129
diff changeset
1
422
ff59e4a1a600 libs.hashes: Better error message when method not available
Matthew Wild <mwild1@gmail.com>
parents: 421
diff changeset
2 local function not_available(_, method_name)
ff59e4a1a600 libs.hashes: Better error message when method not available
Matthew Wild <mwild1@gmail.com>
parents: 421
diff changeset
3 error("Hash method "..method_name.." not available", 2);
414
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
4 end
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
5
422
ff59e4a1a600 libs.hashes: Better error message when method not available
Matthew Wild <mwild1@gmail.com>
parents: 421
diff changeset
6 local _M = setmetatable({}, { __index = not_available });
129
c0be31a5ff55 libs.hashes: Pure-Lua util.hashes replacement (depends on util.sha1)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
414
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
8 local function with(mod, f)
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
9 local ok, pkg = pcall(require, mod);
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
10 if ok then f(pkg); end
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
11 end
389
bf3a4fcdcb76 libs.hashes: Wrap LuaCrypto with fallback to util.sha1
Kim Alvefur <zash@zash.se>
parents: 129
diff changeset
12
443
89526c890363 libs.hashes: Add back pure Lua sha1 implementation
Kim Alvefur <zash@zash.se>
parents: 422
diff changeset
13 with("util.sha1", function (sha1)
89526c890363 libs.hashes: Add back pure Lua sha1 implementation
Kim Alvefur <zash@zash.se>
parents: 422
diff changeset
14 _M.sha1 = sha1.sha1;
89526c890363 libs.hashes: Add back pure Lua sha1 implementation
Kim Alvefur <zash@zash.se>
parents: 422
diff changeset
15 end);
89526c890363 libs.hashes: Add back pure Lua sha1 implementation
Kim Alvefur <zash@zash.se>
parents: 422
diff changeset
16
414
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
17 with("bgcrypto.md5", function (md5)
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
18 _M.md5 = md5.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
19 _M.hmac_md5 = md5.hmac.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
20 end);
389
bf3a4fcdcb76 libs.hashes: Wrap LuaCrypto with fallback to util.sha1
Kim Alvefur <zash@zash.se>
parents: 129
diff changeset
21
414
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
22 with("bgcrypto.sha1", function (sha1)
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
23 _M.sha1 = sha1.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
24 _M.hmac_sha1 = sha1.hmac.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
25 _M.scram_Hi_sha1 = function (p, s, i) return sha1.pbkdf2(p, s, i, 20); end;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
26 end);
389
bf3a4fcdcb76 libs.hashes: Wrap LuaCrypto with fallback to util.sha1
Kim Alvefur <zash@zash.se>
parents: 129
diff changeset
27
414
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
28 with("bgcrypto.sha256", function (sha256)
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
29 _M.sha256 = sha256.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
30 _M.hmac_sha256 = sha256.hmac.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
31 end);
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
32
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
33 with("bgcrypto.sha512", function (sha512)
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
34 _M.sha512 = sha512.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
35 _M.hmac_sha512 = sha512.hmac.digest;
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
36 end);
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
37
421
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
38 with("sha1", function (sha1)
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
39 _M.sha1 = function (data, hex)
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
40 if hex then
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
41 return sha1.sha1(data);
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
42 else
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
43 return (sha1.binary(data));
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
44 end
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
45 end;
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
46 end);
f35cfdff31b6 libs.hashes: Add support for sha1 lib from luarocks
Matthew Wild <mwild1@gmail.com>
parents: 414
diff changeset
47
414
2a5eff919f4a libs.hashes: Switch to moteus bgcrypto suite
Kim Alvefur <zash@zash.se>
parents: 398
diff changeset
48 return _M;