2 -- Copyright (C) 2008-2017 Matthew Wild
3 -- Copyright (C) 2008-2017 Waqas Hussain
4 -- Copyright (C) 2008-2017 Kim Alvefur
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
10 local s_gsub
= string.gsub;
11 local random_bytes
= require
"util.random".bytes
;
12 local base64_encode
= require
"util.encodings".base64
.encode
;
14 local b64url
= { ["+"] = "-", ["/"] = "_", ["="] = "" };
15 local function b64url_random(len
)
16 return (s_gsub(base64_encode(random_bytes(len
)), "[+/=]", b64url
));
20 short
= function () return b64url_random(6); end;
21 medium
= function () return b64url_random(12); end;
22 long
= function () return b64url_random(24); end;
23 custom
= function (size
)
24 return function () return b64url_random(size
); end;