Software /
code /
prosody
File
util/id.lua @ 12633:5d8b0e0b9d48
util.datetime: Remove a line
No idea why the locals were declared on a line by itself. Perhaps line
length considerations? But saving 6 characters in width by adding a
whole line with 47 characters seems excessive.
This is still within the 150 character limit set by .luacheckrc
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 17 Aug 2022 18:07:31 +0200 |
parent | 12111:f8d280215633 |
child | 12975:d10957394a3c |
line wrap: on
line source
-- Prosody IM -- Copyright (C) 2008-2017 Matthew Wild -- Copyright (C) 2008-2017 Waqas Hussain -- Copyright (C) 2008-2017 Kim Alvefur -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- local s_gsub = string.gsub; local random_bytes = require "util.random".bytes; local base64_encode = require "util.encodings".base64.encode; local b64url = { ["+"] = "-", ["/"] = "_", ["="] = "" }; local function b64url_random(len) return (s_gsub(base64_encode(random_bytes(len)), "[+/=]", b64url)); end return { -- sizes divisible by 3 fit nicely into base64 without padding== -- for short lived things with low risk of collisions tiny = function() return b64url_random(3); end; -- close to 8 bytes, should be good enough for relatively short lived or uses -- scoped by host or users, half the size of an uuid short = function() return b64url_random(9); end; -- more entropy than uuid at 2/3 the size -- should be okay for globally scoped ids or security token medium = function() return b64url_random(18); end; -- as long as an uuid but MOAR entropy long = function() return b64url_random(27); end; -- pick your own adventure custom = function (size) return function () return b64url_random(size); end; end; }