1-- Prosody IM 2-- Copyright (C) 2008-2017 Matthew Wild 3-- Copyright (C) 2008-2017 Waqas Hussain 4-- Copyright (C) 2008-2017 Kim Alvefur 5-- 6-- This project is MIT/X11 licensed. Please see the 7-- COPYING file in the source package for more information. 8-- 9 10local s_gsub = string.gsub; 11local random_bytes = require "util.random".bytes; 12local base64_encode = require "util.encodings".base64.encode; 13 14local b64url = { ["+"] = "-", ["/"] = "_", ["="] = "" }; 15local function b64url_random(len) 16 return (s_gsub(base64_encode(random_bytes(len)), "[+/=]", b64url)); 17end 18 19return { 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; 25 end; 26} 27