util/random.lua

Thu, 23 Mar 2023 18:56:32 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 23 Mar 2023 18:56:32 +0000
changeset 485
c9a144591649
parent 401
7be4ebefd1f4
permissions
-rw-r--r--

component: Avoid adding to the global stream metatable

This allows component and client connections to be made side-by-side.
Previous to this change, loading this connection module would break the
ability to make client connections, due to overriding stream methods such as
:reopen() and :reset().

A next step would be to share the methods that the two connection modules have
in common.

-- Prosody IM
-- Copyright (C) 2008-2014 Matthew Wild
-- Copyright (C) 2008-2014 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--

local urandom = io.open("/dev/urandom", "r");

if urandom then
	return {
		seed = function () end;
		bytes = function (n) return urandom:read(n); end
	};
end

local crypto = require "crypto"
return crypto.rand;

mercurial