Software / code / verse
Comparison
libs/hashes.lua @ 422:ff59e4a1a600
libs.hashes: Better error message when method not available
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 27 Jun 2018 19:18:06 +0100 |
| parent | 421:f35cfdff31b6 |
| child | 443:89526c890363 |
comparison
equal
deleted
inserted
replaced
| 421:f35cfdff31b6 | 422:ff59e4a1a600 |
|---|---|
| 1 | 1 |
| 2 local function not_available() | 2 local function not_available(_, method_name) |
| 3 error("not available", 2); | 3 error("Hash method "..method_name.." not available", 2); |
| 4 end | 4 end |
| 5 | 5 |
| 6 local _M = { | 6 local _M = setmetatable({}, { __index = not_available }); |
| 7 md5 = not_available; | |
| 8 hmac_md5 = not_available; | |
| 9 | |
| 10 sha1 = not_available; | |
| 11 hmac_sha1 = not_available; | |
| 12 scram_Hi_sha1 = not_available; | |
| 13 | |
| 14 sha256 = not_available; | |
| 15 hmac_sha256 = not_available; | |
| 16 | |
| 17 sha512 = not_available; | |
| 18 hmac_sha512 = not_available; | |
| 19 }; | |
| 20 | 7 |
| 21 local function with(mod, f) | 8 local function with(mod, f) |
| 22 local ok, pkg = pcall(require, mod); | 9 local ok, pkg = pcall(require, mod); |
| 23 if ok then f(pkg); end | 10 if ok then f(pkg); end |
| 24 end | 11 end |