Mercurial > prosody-hg
comparison util/uuid.lua @ 7063:bc1b375f379e
Merge 0.10->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 08 Jan 2016 16:21:05 +0100 |
| parents | eda0feeaf759 |
| children | ec17115e3721 |
comparison
equal
deleted
inserted
replaced
| 7048:b58fd349ddfe | 7063:bc1b375f379e |
|---|---|
| 14 local function get_nibbles(n) | 14 local function get_nibbles(n) |
| 15 return hex(random_bytes(m_ceil(n/2))):sub(1, n); | 15 return hex(random_bytes(m_ceil(n/2))):sub(1, n); |
| 16 end | 16 end |
| 17 | 17 |
| 18 local function get_twobits() | 18 local function get_twobits() |
| 19 return ("%x"):format(get_nibbles(1):byte() % 4 + 8); | 19 return ("%x"):format(random_bytes(1):byte() % 4 + 8); |
| 20 end | 20 end |
| 21 | 21 |
| 22 local function generate() | 22 local function generate() |
| 23 -- generate RFC 4122 complaint UUIDs (version 4 - random) | 23 -- generate RFC 4122 complaint UUIDs (version 4 - random) |
| 24 return get_nibbles(8).."-"..get_nibbles(4).."-4"..get_nibbles(3).."-"..(get_twobits())..get_nibbles(3).."-"..get_nibbles(12); | 24 return get_nibbles(8).."-"..get_nibbles(4).."-4"..get_nibbles(3).."-"..(get_twobits())..get_nibbles(3).."-"..get_nibbles(12); |
