|
1 | 1 | local deps = { |
2 | 2 | { name = "luv", mod = "luv" }, |
3 | | - { name = "ed25519", mod = "ed25519" }, |
4 | 3 | { name = "lsqlite3", mod = "lsqlite3" }, |
5 | 4 | { name = "cjson", mod = "cjson.safe" }, |
6 | 5 | { name = "luaossl", mod = "openssl" }, |
7 | 6 | { name = "sodium", mod = "sodium" }, |
8 | 7 | } |
9 | 8 |
|
| 9 | +local function require_any(label, modules) |
| 10 | + for _, m in ipairs(modules) do |
| 11 | + local ok = pcall(require, m) |
| 12 | + if ok then |
| 13 | + io.stdout:write(string.format("%-10s: available (%s)\n", label, m)) |
| 14 | + return true |
| 15 | + end |
| 16 | + end |
| 17 | + io.stdout:write(string.format("%-10s: missing\n", label)) |
| 18 | + return false |
| 19 | +end |
| 20 | + |
| 21 | +-- core deps |
10 | 22 | for _, d in ipairs(deps) do |
11 | | - local ok, _ = pcall(require, d.mod) |
12 | | - io.stdout:write(string.format("%-10s: %s\n", d.name, ok and "available" or "missing")) |
13 | | - if not ok then os.exit(1) end |
| 23 | + if not require_any(d.name, { d.mod }) then os.exit(1) end |
14 | 24 | end |
15 | 25 |
|
16 | | --- Fail-closed if sodium (for ed25519) is missing when signatures are required |
| 26 | +-- Ed25519 signer: allow either ed25519 rock or sodium providing crypto_sign_* API |
| 27 | +local ed25519_ok = require_any("ed25519", { "ed25519", "sodium" }) |
| 28 | +if not ed25519_ok then os.exit(1) end |
| 29 | + |
| 30 | +-- Fail-closed if signatures required and no sodium available (used for ed25519) |
17 | 31 | if os.getenv("AUTH_REQUIRE_SIGNATURE") == "1" then |
18 | | - local ok_sodium, _ = pcall(require, "sodium") |
| 32 | + local ok_sodium = pcall(require, "sodium") |
19 | 33 | if not ok_sodium then |
20 | 34 | io.stderr:write("sodium module missing but AUTH_REQUIRE_SIGNATURE=1\n") |
21 | 35 | os.exit(1) |
|
0 commit comments