comparison util/id.lua @ 12110:b5b799a2a10c

util.id: Adjust entropy levels, with rationales Modules using ids for logging should not need the now pretty large medium one.
author Kim Alvefur <zash@zash.se>
date Thu, 02 Dec 2021 01:14:55 +0100
parents 9546c629289b
children f8d280215633
comparison
equal deleted inserted replaced
12109:83bec90a352c 12110:b5b799a2a10c
15 local function b64url_random(len) 15 local function b64url_random(len)
16 return (s_gsub(base64_encode(random_bytes(len)), "[+/=]", b64url)); 16 return (s_gsub(base64_encode(random_bytes(len)), "[+/=]", b64url));
17 end 17 end
18 18
19 return { 19 return {
20 short = function () return b64url_random(6); end; 20 -- sizes divisible by 3 fit nicely into base64 without padding==
21 medium = function () return b64url_random(12); end; 21
22 long = function () return b64url_random(24); end; 22 -- close to 8 bytes, should be good enough for relatively short lived or uses
23 -- scoped by host or users, half the size of an uuid
24 short = function() return b64url_random(9); end;
25
26 -- more entropy than uuid at 2/3 the size
27 -- should be okay for globally scoped ids or security token
28 medium = function() return b64url_random(18); end;
29
30 -- as long as an uuid but MOAR entropy
31 long = function() return b64url_random(27); end;
32
33 -- pick your own adventure
23 custom = function (size) 34 custom = function (size)
24 return function () return b64url_random(size); end; 35 return function () return b64url_random(size); end;
25 end; 36 end;
26 } 37 }