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>
impl<'a> Validator<'a>
Sourcepub const fn new() -> Self
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.
Sourcepub const fn require_fingerprint(self) -> Self
pub const fn require_fingerprint(self) -> Self
Refuses a message without FINGERPRINT (Rejection::FingerprintMissing).
Sourcepub const fn known_attributes(self, known: &'a [AttrType]) -> Self
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.
Sourcepub const fn allow_truncated_sha256(self, min_len: usize) -> Self
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).
Sourcepub fn authenticate(
&self,
m: &Message,
key: &[u8],
crypto: &dyn RTCCrypto,
) -> Result<ValidatedMessage, Rejection>
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).
Sourcepub fn authenticate_with(
&self,
m: &Message,
algorithm: IntegrityAlgorithm,
key: &[u8],
crypto: &dyn RTCCrypto,
) -> Result<ValidatedMessage, Rejection>
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.
Sourcepub fn unauthenticated(
&self,
m: &Message,
) -> Result<ValidatedMessage, Rejection>
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.