diff options
author | Matthew Wild <mwild1@gmail.com> | 2022-07-11 14:09:16 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2022-07-11 14:09:16 +0100 |
commit | 4e4c2dd6dc9a7e63070d5ee57332c359d432a4c3 (patch) | |
tree | a4125d54878f8d27691c74e1ff88d52bc9e1578a /util | |
parent | 2db2476824b14ee17f28d0427f8e3b56a5b77a5c (diff) | |
download | prosody-4e4c2dd6dc9a7e63070d5ee57332c359d432a4c3.tar.gz prosody-4e4c2dd6dc9a7e63070d5ee57332c359d432a4c3.zip |
util.paseto: Export similar API to new util.jwt for ease and consistency
Diffstat (limited to 'util')
-rw-r--r-- | util/paseto.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/util/paseto.lua b/util/paseto.lua index c658902c..02a0aa70 100644 --- a/util/paseto.lua +++ b/util/paseto.lua @@ -120,6 +120,27 @@ function v4_public.import_private_key(pem) }, v4_public_privkey_mt); end +function v4_public.init(private_key_pem, public_key_pem, options) + local sign, verify = v4_public.sign, v4_public.verify; + local public_key = public_key_pem and v4_public.import_public_key(public_key_pem); + local private_key = private_key_pem and v4_public.import_private_key(private_key_pem); + local default_footer = options and options.default_footer; + local default_assertion = options and options.default_implicit_assertion; + return private_key and function (token, token_footer, token_assertion) + return sign(token, private_key, token_footer or default_footer, token_assertion or default_assertion); + end, public_key and function (token, expected_footer, token_assertion) + return verify(token, public_key, expected_footer or default_footer, token_assertion or default_assertion); + end; +end + +function v4_public.new_signer(private_key_pem, options) + return (v4_public.init(private_key_pem, nil, options)); +end + +function v4_public.new_verifier(public_key_pem, options) + return (select(2, v4_public.init(public_key_pem, options))); +end + return { pae = pae; v4_public = v4_public; |