MessageRef

Struct MessageRef 

Source
pub struct MessageRef<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> MessageRef<'a>

Source

pub fn method(&self) -> StunMethod

message method.

Source

pub fn token(&self) -> &'a [u8]

message transaction id.

Source

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::stun::attribute::*;
use turn_server::stun::*;

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 = MessageDecoder::decode(&buffer[..], &mut attributes).unwrap();
assert!(message.get::<UserName>().is_none());
Source

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::stun::attribute::*;
use turn_server::stun::*;

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 = MessageDecoder::decode(&buffer[..], &mut attributes).unwrap();

assert_eq!(message.get_all::<UserName>().next(), None);
Source

pub fn integrity(&self, digest: &[u8; 16]) -> Result<(), StunError>

check MessageRefIntegrity attribute.

return whether the MessageRefIntegrity attribute contained in the message can pass the check.

§Test
use std::convert::TryFrom;
use turn_server::stun::*;

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 = MessageDecoder::decode(&buffer[..], &mut attributes).unwrap();
let result = message
    .integrity(&util::long_term_credential_digest(
        "panda",
        "panda",
        "raspberry",
    ))
    .is_ok();
assert!(result);

Trait Implementations§

Source§

impl<'a> Debug for MessageRef<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MessageRef<'a>

§

impl<'a> RefUnwindSafe for MessageRef<'a>

§

impl<'a> Send for MessageRef<'a>

§

impl<'a> Sync for MessageRef<'a>

§

impl<'a> Unpin for MessageRef<'a>

§

impl<'a> UnwindSafe for MessageRef<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,