libs.hashes: Better error message when method not available

Wed, 27 Jun 2018 19:18:06 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 27 Jun 2018 19:18:06 +0100
changeset 422
ff59e4a1a600
parent 421
f35cfdff31b6
child 423
e98cef597393

libs.hashes: Better error message when method not available

libs/hashes.lua file | annotate | diff | comparison | revisions
--- a/libs/hashes.lua	Wed Jun 27 19:17:51 2018 +0100
+++ b/libs/hashes.lua	Wed Jun 27 19:18:06 2018 +0100
@@ -1,22 +1,9 @@
 
-local function not_available()
-	error("not available", 2);
+local function not_available(_, method_name)
+	error("Hash method "..method_name.." not available", 2);
 end
 
-local _M = {
-	md5 = not_available;
-	hmac_md5 = not_available;
-
-	sha1 = not_available;
-	hmac_sha1 = not_available;
-	scram_Hi_sha1 = not_available;
-
-	sha256 = not_available;
-	hmac_sha256 = not_available;
-
-	sha512 = not_available;
-	hmac_sha512 = not_available;
-};
+local _M = setmetatable({}, { __index = not_available });
 
 local function with(mod, f)
 	local ok, pkg = pcall(require, mod);

mercurial