1#![deny(missing_debug_implementations)]
10#![deny(missing_docs)]
11
12pub use stun_types as stun;
24use stun_types::message::LongTermCredentials;
25pub mod attribute;
26pub mod channel;
27pub mod message;
28
29pub fn debug_init() {
31 attribute::attributes_init();
32}
33
34#[derive(Debug, Clone)]
36pub struct TurnCredentials {
37 username: String,
38 password: String,
39}
40
41impl TurnCredentials {
42 pub fn into_long_term_credentials(self, realm: &str) -> LongTermCredentials {
44 LongTermCredentials::new(self.username, self.password, realm.to_string())
45 }
46
47 pub fn new(username: &str, password: &str) -> Self {
49 Self {
50 username: username.to_owned(),
51 password: password.to_owned(),
52 }
53 }
54
55 pub fn username(&self) -> &str {
57 &self.username
58 }
59
60 pub fn password(&self) -> &str {
62 &self.password
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use tracing::subscriber::DefaultGuard;
69 use tracing_subscriber::layer::SubscriberExt;
70 use tracing_subscriber::Layer;
71
72 pub fn test_init_log() -> DefaultGuard {
73 crate::debug_init();
74 let level_filter = std::env::var("TURN_LOG")
75 .or(std::env::var("RUST_LOG"))
76 .ok()
77 .and_then(|var| var.parse::<tracing_subscriber::filter::Targets>().ok())
78 .unwrap_or(
79 tracing_subscriber::filter::Targets::new().with_default(tracing::Level::TRACE),
80 );
81 let registry = tracing_subscriber::registry().with(
82 tracing_subscriber::fmt::layer()
83 .with_file(true)
84 .with_line_number(true)
85 .with_level(true)
86 .with_target(false)
87 .with_test_writer()
88 .with_filter(level_filter),
89 );
90 tracing::subscriber::set_default(registry)
91 }
92}