util.jwt: Add new init() convenience method to obtain both signer and verifier
authorMatthew Wild <mwild1@gmail.com>
Mon, 11 Jul 2022 13:43:01 +0100
changeset 12711 f75235110045
parent 12710 108b1758bd8d
child 12712 9953ac7b0c15
util.jwt: Add new init() convenience method to obtain both signer and verifier
util/jwt.lua
--- a/util/jwt.lua	Mon Jul 11 13:42:08 2022 +0100
+++ b/util/jwt.lua	Mon Jul 11 13:43:01 2022 +0100
@@ -197,9 +197,15 @@
 	end
 end
 
+local function init(algorithm, private_key, public_key, options)
+	return new_signer(algorithm, private_key, options), new_verifier(algorithm, public_key or private_key, options);
+end
+
 return {
+	init = init;
 	new_signer = new_signer;
 	new_verifier = new_verifier;
+	-- Exported mainly for tests
 	_algorithms = algorithms;
 	-- Deprecated
 	sign = algorithms.HS256.sign;