pub struct Message<'a> { /* private fields */ }Implementations§
Source§impl<'a> Message<'a>
impl<'a> Message<'a>
Sourcepub fn transaction_id(&self) -> &'a [u8] ⓘ
pub fn transaction_id(&self) -> &'a [u8] ⓘ
message transaction id.
Sourcepub fn get<T: Attribute<'a>>(&self) -> Option<T::Item>
pub fn get<T: Attribute<'a>>(&self) -> Option<T::Item>
get attribute.
get attribute from message attribute list.
§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;
let buffer = [
0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];
let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();
assert!(message.get::<UserName>().is_none());Sourcepub fn get_for_type(&self, attr_type: AttributeType) -> Option<&'a [u8]>
pub fn get_for_type(&self, attr_type: AttributeType) -> Option<&'a [u8]>
get attribute for type.
get attribute from message attribute list.
§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;
let buffer = [
0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];
let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();
assert!(message.get_for_type(AttributeType::UserName).is_none());Sourcepub fn get_all<T: Attribute<'a>>(&self) -> impl Iterator<Item = T::Item>
pub fn get_all<T: Attribute<'a>>(&self) -> impl Iterator<Item = T::Item>
Gets all the values of an attribute from a list.
Normally a stun message can have multiple attributes with the same name, and this function will all the values of the current attribute.
§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;
let buffer = [
0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];
let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();
assert_eq!(message.get_all::<UserName>().next(), None);Sourcepub fn verify(&self, password: &Password) -> Result<(), Error>
pub fn verify(&self, password: &Password) -> Result<(), Error>
check MessageRefIntegrity attribute.
return whether the MessageRefIntegrity attribute contained in the message
can pass the check.
§Test
use std::convert::TryFrom;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;
let buffer = [
0x00u8, 0x03, 0x00, 0x50, 0x21, 0x12, 0xa4, 0x42, 0x64, 0x4f, 0x5a,
0x78, 0x6a, 0x56, 0x33, 0x62, 0x4b, 0x52, 0x33, 0x31, 0x00, 0x19, 0x00,
0x04, 0x11, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x05, 0x70, 0x61, 0x6e,
0x64, 0x61, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x09, 0x72, 0x61, 0x73,
0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00,
0x10, 0x31, 0x63, 0x31, 0x33, 0x64, 0x32, 0x62, 0x32, 0x34, 0x35, 0x62,
0x33, 0x61, 0x37, 0x33, 0x34, 0x00, 0x08, 0x00, 0x14, 0xd6, 0x78, 0x26,
0x99, 0x0e, 0x15, 0x56, 0x15, 0xe5, 0xf4, 0x24, 0x74, 0xe2, 0x3c, 0x26,
0xc5, 0xb1, 0x03, 0xb2, 0x6d,
];
let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();
let result = message
.verify(&turn_server::codec::crypto::generate_password(
"panda",
"panda",
"raspberry",
turn_server::codec::message::attributes::PasswordAlgorithm::Md5,
))
.is_ok();
assert!(result);Sourcepub fn decode(
bytes: &'a [u8],
attributes: &'a mut Attributes,
) -> Result<Self, Error>
pub fn decode( bytes: &'a [u8], attributes: &'a mut Attributes, ) -> Result<Self, Error>
§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;
let buffer: [u8; 20] = [
0x00, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49, 0x42,
0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];
let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();
assert_eq!(
message.method(),
Method::Binding(MethodType::Request)
);
assert!(message.get::<UserName>().is_none());Sourcepub fn message_size(buffer: &[u8]) -> Result<usize, Error>
pub fn message_size(buffer: &[u8]) -> Result<usize, Error>
§Test
use turn_server::codec::message::*;
let buffer: [u8; 20] = [
0x00, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49, 0x42,
0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];
let size = Message::message_size(&buffer[..]).unwrap();
assert_eq!(size, 20);Auto Trait Implementations§
impl<'a> Freeze for Message<'a>
impl<'a> RefUnwindSafe for Message<'a>
impl<'a> Send for Message<'a>
impl<'a> Sync for Message<'a>
impl<'a> Unpin for Message<'a>
impl<'a> UnwindSafe for Message<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request