Mercurial > prosody-hg
comparison util/id.lua @ 12111:f8d280215633
util.id: Add a 'tiny' variant
Conversations uses this for its randomized resources. Presumably fine
and collision resistant enough when you have a few devices at most.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 02 Dec 2021 00:13:23 +0100 |
| parents | b5b799a2a10c |
| children | d10957394a3c |
comparison
equal
deleted
inserted
replaced
| 12110:b5b799a2a10c | 12111:f8d280215633 |
|---|---|
| 17 end | 17 end |
| 18 | 18 |
| 19 return { | 19 return { |
| 20 -- sizes divisible by 3 fit nicely into base64 without padding== | 20 -- sizes divisible by 3 fit nicely into base64 without padding== |
| 21 | 21 |
| 22 -- for short lived things with low risk of collisions | |
| 23 tiny = function() return b64url_random(3); end; | |
| 24 | |
| 22 -- close to 8 bytes, should be good enough for relatively short lived or uses | 25 -- 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 | 26 -- scoped by host or users, half the size of an uuid |
| 24 short = function() return b64url_random(9); end; | 27 short = function() return b64url_random(9); end; |
| 25 | 28 |
| 26 -- more entropy than uuid at 2/3 the size | 29 -- more entropy than uuid at 2/3 the size |
