rtc_ice/rand/
mod.rs

1use shared::util::generate_crypto_random_string;
2
3#[cfg(test)]
4mod rand_test;
5
6const RUNES_ALPHA: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
7const RUNES_CANDIDATE_ID_FOUNDATION: &[u8] =
8    b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+";
9
10const LEN_UFRAG: usize = 16;
11const LEN_PWD: usize = 32;
12
13/// <https://tools.ietf.org/html/rfc5245#section-15.1>
14/// candidate-id = "candidate" ":" foundation
15/// foundation   = 1*32ice-char
16/// ice-char     = ALPHA / DIGIT / "+" / "/"
17pub fn generate_cand_id() -> String {
18    format!(
19        "candidate:{}",
20        generate_crypto_random_string(32, RUNES_CANDIDATE_ID_FOUNDATION)
21    )
22}
23
24/// Generates ICE pwd.
25/// This internally uses `generate_crypto_random_string`.
26pub fn generate_pwd() -> String {
27    generate_crypto_random_string(LEN_PWD, RUNES_ALPHA)
28}
29
30/// ICE user fragment.
31/// This internally uses `generate_crypto_random_string`.
32pub fn generate_ufrag() -> String {
33    generate_crypto_random_string(LEN_UFRAG, RUNES_ALPHA)
34}