Skip to main content

Validator

Struct Validator 

Source
pub struct Validator<'a> { /* private fields */ }
Expand description

The checks a usage applies to every message it receives.

The default checks a FINGERPRINT that is present and knows no usage attributes; a usage states its own rules once and keeps the value:

  • require_fingerprint: the usage sends FINGERPRINT in every message (ICE does, RFC 8445 section 7.1), so a message without one is not for it;
  • known_attributes: the comprehension-required attributes the usage understands; any other fails the message (RFC 8489 sections 6.3.1 to 6.3.4);
  • allow_truncated_sha256: the usage allows a truncated MESSAGE-INTEGRITY-SHA256 (RFC 8489 section 14.6).

Implementations§

Source§

impl<'a> Validator<'a>

Source

pub const fn new() -> Self

A validator that checks FINGERPRINT when it is present, takes MESSAGE-INTEGRITY-SHA256 only whole, and does not look for unknown attributes.

Source

pub const fn require_fingerprint(self) -> Self

Refuses a message without FINGERPRINT (Rejection::FingerprintMissing).

Source

pub const fn known_attributes(self, known: &'a [AttrType]) -> Self

Refuses a message that carries a comprehension-required attribute outside known (Rejection::UnknownAttributes). known is STUN_ATTRIBUTES plus the usage’s own.

Source

pub const fn allow_truncated_sha256(self, min_len: usize) -> Self

Accepts a MESSAGE-INTEGRITY-SHA256 truncated to min_len bytes or more (never fewer than 16, RFC 8489 section 14.6).

Source

pub fn authenticate( &self, m: &Message, key: &[u8], crypto: &dyn RTCCrypto, ) -> Result<ValidatedMessage, Rejection>

Checks a message that must be authenticated with key.

RFC 8489 sections 9.1.3 and 9.2.4: MESSAGE-INTEGRITY-SHA256 is verified when the message has it, MESSAGE-INTEGRITY otherwise. ValidatedMessage::integrity says which, so a response can be sent with the same one (section 9.1.3).

§Errors

The Rejection that says which check failed. In order: FINGERPRINT, integrity, unknown attributes (RFC 8489 section 6.3).

Source

pub fn authenticate_with( &self, m: &Message, algorithm: IntegrityAlgorithm, key: &[u8], crypto: &dyn RTCCrypto, ) -> Result<ValidatedMessage, Rejection>

Checks a message that must be authenticated with key by the integrity attribute of algorithm, whatever else it carries.

This is the check for a response when the request carried one integrity attribute (RFC 8489 section 9.1.4: “the algorithm in the response has to match”) and for everything after the first response (section 9.1.5).

§Errors

As authenticate; a message without that attribute is Rejection::IntegrityMissing.

Source

pub fn unauthenticated( &self, m: &Message, ) -> Result<ValidatedMessage, Rejection>

Checks a message that is not authenticated: FINGERPRINT and unknown attributes only.

For a usage or a message without credentials: a Binding indication, the response of a public STUN server, the 401 that starts the long-term mechanism. If the message does carry an integrity attribute, it is not verified and ValidatedMessage::integrity is None, but the attributes after it are still left out, as RFC 8489 section 9 requires of every agent.

§Errors

The Rejection that says which check failed.

Trait Implementations§

Source§

impl<'a> Clone for Validator<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Validator<'a>

Source§

impl<'a> Debug for Validator<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Validator<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Validator<'a>

§

impl<'a> Freeze for Validator<'a>

§

impl<'a> Move for Validator<'a>

§

impl<'a> RefUnwindSafe for Validator<'a>

§

impl<'a> Send for Validator<'a>

§

impl<'a> Sync for Validator<'a>

§

impl<'a> Unpin for Validator<'a>

§

impl<'a> UnsafeUnpin for Validator<'a>

§

impl<'a> UnwindSafe for Validator<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.