Software /
code /
prosody
Changeset
12711:9e9f158d6699
util.paseto: Export similar API to new util.jwt for ease and consistency
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 11 Jul 2022 14:09:16 +0100 |
parents | 12710:2dbb3335cd34 |
children | 12712:719a72f14e90 |
files | util/paseto.lua |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/paseto.lua Mon Jul 11 14:08:55 2022 +0100 +++ b/util/paseto.lua Mon Jul 11 14:09:16 2022 +0100 @@ -120,6 +120,27 @@ }, 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;