pub struct Message { /* private fields */ }Expand description
A STUN message: the header, the attributes, and — once decoded — what the two integrity values said.
Implementations§
Source§impl Message
impl Message
Sourcepub const fn new(class: Class, transaction: TransactionId) -> Self
pub const fn new(class: Class, transaction: TransactionId) -> Self
An empty Binding message of this class.
Sourcepub fn with(self, attribute: Attribute) -> Self
pub fn with(self, attribute: Attribute) -> Self
Append an attribute.
Order is preserved, and only two attributes have a normative position: the two
Message::encode appends itself.
Sourcepub const fn transaction(&self) -> TransactionId
pub const fn transaction(&self) -> TransactionId
The transaction this message belongs to.
Sourcepub fn attributes(&self) -> &[Attribute]
pub fn attributes(&self) -> &[Attribute]
The attributes, in the order they appeared.
Sourcepub fn encode(&self, key: Option<&str>) -> Result<Vec<u8>, Error>
pub fn encode(&self, key: Option<&str>) -> Result<Vec<u8>, Error>
Encode, appending MESSAGE-INTEGRITY keyed with key when there is one, and then
FINGERPRINT, in that order and always last (RFC 5389 §15.4, §15.5).
key is None only for RFC 8445 §11’s keepalive, which “MUST NOT utilize any
authentication mechanism”. FINGERPRINT is not optional: spec §11.1 puts it on every
check, every response and every keepalive, and it is what lets the far end tell a check
from RTP on the one port they share.
Sourcepub fn decode(datagram: &[u8]) -> Result<Self, Error>
pub fn decode(datagram: &[u8]) -> Result<Self, Error>
Read a datagram the media port’s demultiplexer called STUN (RFC 5764 §5.1.2,
crate::dtls::classify).
Nothing here trusts the datagram. A FINGERPRINT that does not match is an error, per
RFC 5389 §15.5, because a message whose CRC is wrong is not addressed to us however well
formed it is; a MESSAGE-INTEGRITY cannot be checked yet, because which key applies
depends on the USERNAME this message carries — see Message::verify_integrity.
Sourcepub fn verify_integrity(&self, key: &str) -> bool
pub fn verify_integrity(&self, key: &str) -> bool
Whether this message’s MESSAGE-INTEGRITY was computed with key.
false when there is none at all: an unauthenticated check is not a check that happens
to verify, and spec §11.3 requires that it move no state.
Which key to pass is the direction rule — Peering::inbound_key for a check that
arrived, Peering::outbound_key for the response to one sipx sent.
Sourcepub const fn has_integrity(&self) -> bool
pub const fn has_integrity(&self) -> bool
Whether a MESSAGE-INTEGRITY was present at all.
Sourcepub const fn has_fingerprint(&self) -> bool
pub const fn has_fingerprint(&self) -> bool
Whether a FINGERPRINT was present. If it was, it matched — Message::decode rejects
one that does not.
Sourcepub fn priority(&self) -> Option<Priority>
pub fn priority(&self) -> Option<Priority>
The PRIORITY a check claims for the candidate the peer would learn from it (§7.1.1).
Sourcepub fn use_candidate(&self) -> bool
pub fn use_candidate(&self) -> bool
Whether USE-CANDIDATE is set (§7.1.2).
Sourcepub fn role(&self) -> Option<RoleAttribute>
pub fn role(&self) -> Option<RoleAttribute>
The role attribute and its tiebreaker, if the peer sent one (§7.1.3).
A peer that sends neither is not doing role signalling, which spec §7.3’s last row says
is not a conflict. nominate reports USE-CANDIDATE alongside ICE-CONTROLLING; a
controlled peer that sets it anyway is violating §7.1.2, and the caller sees that as a
Controlled role with Message::use_candidate true.
Sourcepub fn error_code(&self) -> Option<u16>
pub fn error_code(&self) -> Option<u16>
The ERROR-CODE, if this is an error response. 487 is the role conflict of §7.3.1.1.
Sourcepub fn mapped_address(&self) -> Option<SocketAddr>
pub fn mapped_address(&self) -> Option<SocketAddr>
The XOR-MAPPED-ADDRESS, unobfuscated.
Trait Implementations§
impl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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