Xirsys.XTurn.Auth.UUID (xturn v2.0.0)

Copy Markdown View Source

Random identifiers and hex encoding for TURN credential challenges.

What problem this solves

Long-term STUN/TURN authentication needs unpredictable nonces and usernames on the wire. This module produces lowercase hex strings from cryptographically random bytes and time-prefixed nonce material without an external UUID library.

Internal: called by Auth.NonceStore and Auth.Client during credential provisioning and 401 challenge issuance.

RFCs

  • RFC 8489 (long-term credentials, NONCE attribute, MESSAGE-INTEGRITY)
  • RFC 5389 (STUN long-term credential mechanism, legacy interop)

Summary

Functions

Returns 32 lowercase hex characters from 16 cryptographically random bytes.

Maps a nibble (0-15) to its lowercase hex ASCII code.

Hex-encodes a binary, byte list, or empty list to lowercase ASCII char codes.

Returns a time-prefixed nonce binary for credential challenges.

Functions

random()

Returns 32 lowercase hex characters from 16 cryptographically random bytes.

to_digit(n)

Maps a nibble (0-15) to its lowercase hex ASCII code.

Parameters

  • n - integer from 0 to 15

Examples

iex> Xirsys.XTurn.Auth.UUID.to_digit(9)
57

iex> Xirsys.XTurn.Auth.UUID.to_digit(10)
97

to_hex(bin)

Hex-encodes a binary, byte list, or empty list to lowercase ASCII char codes.

Examples

iex> Xirsys.XTurn.Auth.UUID.to_hex(<<0xAB, 0x0C>>)
~c"ab0c"

iex> Xirsys.XTurn.Auth.UUID.to_hex([])
[]

utc_random()

Returns a time-prefixed nonce binary for credential challenges.

The prefix is 14 uppercase hex digits of microseconds since the Unix epoch, followed by 18 lowercase hex characters from 9 random bytes.