Annotate

util/random.lua @ 445:b119dc4d8bc2

plugins.smacks: Don't warn about zero stanzas acked It's only if the count somehow goes backwards that something is really wrong. An ack for zero stanzas is fine and we don't need to do anything.
author Kim Alvefur <zash@zash.se>
date Thu, 10 Jun 2021 11:58:23 +0200
parent 401:7be4ebefd1f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
388
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Prosody IM
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2008-2014 Matthew Wild
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 -- Copyright (C) 2008-2014 Waqas Hussain
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 --
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 --
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
401
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
9 local urandom = io.open("/dev/urandom", "r");
388
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
401
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
11 if urandom then
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
12 return {
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
13 seed = function () end;
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
14 bytes = function (n) return urandom:read(n); end
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
15 };
388
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end
d963c8a5d89c Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
401
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
18 local crypto = require "crypto"
7be4ebefd1f4 util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents: 388
diff changeset
19 return crypto.rand;