Mercurial > prosody-hg
changeset 13983:837d47c24e3f 13.0
util.uuid: Update UUIDv7 to match RFC 9562
The data layout changed a bit since draft-peabody-dispatch-new-uuid-format-01
Main change is being based on milliseconds instead of seconds and
slightly more entropy.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 10 Oct 2025 17:18:51 +0200 |
| parents | 2041c347c178 |
| children | 70de03ca79a8 9cfc62b4625b |
| files | doc/doap.xml util/uuid.lua |
| diffstat | 2 files changed, 6 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/doap.xml Mon Oct 06 01:22:40 2025 +0200 +++ b/doc/doap.xml Fri Oct 10 17:18:51 2025 +0200 @@ -65,6 +65,7 @@ <implements rdf:resource="https://www.rfc-editor.org/info/rfc8305"/> <implements rdf:resource="https://www.rfc-editor.org/info/rfc9266"/> <implements rdf:resource="https://www.rfc-editor.org/info/rfc9525"/> + <implements rdf:resource="https://www.rfc-editor.org/info/rfc9562"/> <implements rdf:resource="https://datatracker.ietf.org/doc/draft-cridland-xmpp-session/"> <!-- since=0.6.0 note=Added in hg:0bbbc9042361 --> </implements>
--- a/util/uuid.lua Mon Oct 06 01:22:40 2025 +0200 +++ b/util/uuid.lua Fri Oct 10 17:18:51 2025 +0200 @@ -28,15 +28,11 @@ local function generate_v7() -- Sortable based on time and random - -- https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-01#section-4.4 - local t = time.now(); - local unixts = m_floor(t); - local unixts_a = m_floor(unixts / 16); - local unixts_b = m_floor(unixts % 16); - local subsec = t % 1; - local subsec_a = m_floor(subsec * 0x1000); - local subsec_b = m_floor(subsec * 0x1000000) % 0x1000; - return ("%08x-%x%03x-7%03x-%4s-%12s"):format(unixts_a, unixts_b, subsec_a, subsec_b, get_twobits() .. get_nibbles(3), get_nibbles(12)); + -- https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7 + local unix_ts_ms = m_floor(time.now()*1000); + local unix_ts_ms_a = m_floor(unix_ts_ms / 0x10000); + local unix_ts_ms_b = unix_ts_ms % 0x10000; + return ("%08x-%4x-7%3s-%1s%3s-%12s"):format(unix_ts_ms_a, unix_ts_ms_b, get_nibbles(3), get_twobits(), get_nibbles(3), get_nibbles(12)); end return {
