diff --git a/src/bin/allocate_smoke.rs b/src/bin/allocate_smoke.rs index 1073811..9ec3e5e 100644 --- a/src/bin/allocate_smoke.rs +++ b/src/bin/allocate_smoke.rs @@ -1,6 +1,6 @@ use bytes::BytesMut; use niom_turn::constants::*; -use niom_turn::stun; +// use niom_turn::stun; // not needed; use specific functions via path when required use std::net::SocketAddr; use tokio::net::UdpSocket; use std::time::Duration; @@ -20,7 +20,7 @@ async fn main() -> anyhow::Result<()> { let mut buf = BytesMut::new(); buf.extend_from_slice(&METHOD_ALLOCATE.to_be_bytes()); // Allocate Request buf.extend_from_slice(&0u16.to_be_bytes()); // length placeholder - buf.extend_from_slice(&MAGIC_COOKIE_U32.to_be_bytes()); + buf.extend_from_slice(&MAGIC_COOKIE_BYTES); let trans = [13u8; 12]; buf.extend_from_slice(&trans); @@ -34,7 +34,7 @@ async fn main() -> anyhow::Result<()> { // MESSAGE-INTEGRITY placeholder let mi_attr_offset = buf.len(); buf.extend_from_slice(&ATTR_MESSAGE_INTEGRITY.to_be_bytes()); - buf.extend_from_slice(&(20u16).to_be_bytes()); + buf.extend_from_slice(&((HMAC_SHA1_LEN as u16).to_be_bytes())); let mi_val_pos = buf.len(); buf.extend_from_slice(&[0u8;20]); while (buf.len() % 4) != 0 { buf.extend_from_slice(&[0u8]); } @@ -47,10 +47,10 @@ async fn main() -> anyhow::Result<()> { // compute HMAC over bytes up to MI attribute header { - use hmac::{Hmac, Mac}; - use sha1::Sha1; - type HmacSha1 = Hmac; - let mut mac = HmacSha1::new_from_slice(password.as_bytes()).expect("HMAC key"); + use hmac::{Hmac, Mac}; + use sha1::Sha1; + type HmacSha1 = Hmac; + let mut mac = HmacSha1::new_from_slice(password.as_bytes()).expect("HMAC key"); mac.update(&buf[..mi_attr_offset]); let res = mac.finalize().into_bytes(); for i in 0..20 { buf[mi_val_pos + i] = res[i]; } diff --git a/src/bin/smoke_client.rs b/src/bin/smoke_client.rs index e5dc235..af241bb 100644 --- a/src/bin/smoke_client.rs +++ b/src/bin/smoke_client.rs @@ -16,7 +16,7 @@ async fn main() -> anyhow::Result<()> { let mut buf = BytesMut::new(); buf.extend_from_slice(&METHOD_BINDING.to_be_bytes()); // Binding Request buf.extend_from_slice(&0u16.to_be_bytes()); // length placeholder - buf.extend_from_slice(&MAGIC_COOKIE_U32.to_be_bytes()); + buf.extend_from_slice(&MAGIC_COOKIE_BYTES); let trans = [7u8; 12]; buf.extend_from_slice(&trans); @@ -30,7 +30,7 @@ async fn main() -> anyhow::Result<()> { // MESSAGE-INTEGRITY placeholder let mi_attr_offset = buf.len(); buf.extend_from_slice(&ATTR_MESSAGE_INTEGRITY.to_be_bytes()); - buf.extend_from_slice(&(20u16).to_be_bytes()); + buf.extend_from_slice(&((HMAC_SHA1_LEN as u16).to_be_bytes())); let mi_val_pos = buf.len(); buf.extend_from_slice(&[0u8;20]); while (buf.len() % 4) != 0 { buf.extend_from_slice(&[0u8]); } @@ -43,10 +43,10 @@ async fn main() -> anyhow::Result<()> { // compute HMAC over bytes up to MI attribute header { - use hmac::{Hmac, Mac}; - use sha1::Sha1; - type HmacSha1 = Hmac; - let mut mac = HmacSha1::new_from_slice(password.as_bytes()).expect("HMAC key"); + use hmac::{Hmac, Mac}; + use sha1::Sha1; + type HmacSha1 = Hmac; + let mut mac = HmacSha1::new_from_slice(password.as_bytes()).expect("HMAC key"); mac.update(&buf[..mi_attr_offset]); let res = mac.finalize().into_bytes(); for i in 0..20 { buf[mi_val_pos + i] = res[i]; }