Skip to main content

sipx_ua/
auth.rs

1//! Shared HTTP Digest authentication for SIP.
2//!
3//! Parsing, challenge selection and digest arithmetic live in the sans-I/O SIP core so
4//! registration and call setup use one implementation. This module preserves the `sipx-ua` API
5//! and supplies entropy at the runtime-facing layer.
6
7pub use sipx_sip::auth::{
8    Algorithm, Challenge, Credentials, respond, strongest, topmost_supported,
9};
10
11/// A fresh client nonce.
12#[must_use]
13pub fn new_cnonce() -> String {
14    use rand::Rng as _;
15    let value: u64 = rand::rng().random();
16    format!("{value:016x}")
17}
18
19#[cfg(test)]
20#[allow(clippy::panic)]
21mod tests {
22    /// Two cnonces in a row must differ; a fixed one defeats the point of a client nonce.
23    #[test]
24    fn client_nonces_are_not_repeated() {
25        let mut seen = std::collections::HashSet::new();
26        for _ in 0..100 {
27            assert!(seen.insert(super::new_cnonce()), "a cnonce was repeated");
28        }
29    }
30}