#[non_exhaustive]pub struct VerifyPolicy {
pub max_age: Option<Duration>,
pub max_clock_skew_future: Option<Duration>,
pub require_timestamp: bool,
pub cavage_required_headers: &'static [&'static str],
pub rfc9421_required_components: &'static [&'static str],
pub allow_multiple_signatures: bool,
}Expand description
Tunables governing which signed requests are accepted at verification time.
A max_age of None disables the past-side check and a
max_clock_skew_future of None disables the future-side check;
both default to Some(...) in the presets. cavage_required_headers
defaults to CAVAGE_REQUIRED_HEADERS, rfc9421_required_components
defaults to RFC9421_REQUIRED_COMPONENTS, and
allow_multiple_signatures defaults to false — callers that need
the historical permissive behaviour can flip any of these knobs.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_age: Option<Duration>Maximum permissible age of a signature. A created (or Date)
timestamp older than now - max_age is rejected. None
disables the past-side check.
max_clock_skew_future: Option<Duration>Maximum permissible future skew. A timestamp claimed to be more
than max_clock_skew_future ahead of the verifier’s clock is
rejected, to catch badly-set signer clocks and straight-out
forgeries. None disables the future-side check.
require_timestamp: boolIf true, a request carrying neither a created parameter nor
a Date header is rejected. Defaults to false to stay
compatible with servers that only emit one of the two.
cavage_required_headers: &'static [&'static str]Cavage-specific: the list of header names whose presence in the
headers= parameter is mandatory. A signature whose coverage
does not include every name listed here is rejected with
Error::RequiredHeaderAbsent. The names are compared
case-insensitively.
rfc9421_required_components: &'static [&'static str]RFC 9421-specific: the list of component identifiers whose
presence in the Signature-Input: inner list is mandatory.
Matches the spelling returned by
Component::identifier —
derived components are written with a leading @
(e.g. "@method", "@target-uri"), header components
appear lower-cased (e.g. "content-digest"). Names are
compared case-insensitively.
allow_multiple_signatures: boolIf false (the default), a Signature-Input: header containing
more than one label is rejected outright. Mastodon and the RFC
9421 interop profile both expect exactly one signature per
request; permitting additional labels opens a fallback channel
an attacker can use to bypass policy by attaching a second
signature of their own.
Implementations§
Source§impl VerifyPolicy
impl VerifyPolicy
Sourcepub const fn mastodon() -> Self
pub const fn mastodon() -> Self
Returns the policy Mastodon applies to inbound federated requests: 12 hours past, 5 minutes future, timestamps optional, and the Cavage / RFC 9421 minimum component sets enforced.
Sourcepub const fn strict() -> Self
pub const fn strict() -> Self
Returns a tight policy appropriate for internal services where every hop has NTP-synchronised clocks: 5 minutes past, 1 minute future, timestamps mandatory, Cavage / RFC 9421 minimum component sets enforced, and multi-signature requests rejected.
Sourcepub const fn no_freshness_check() -> Self
pub const fn no_freshness_check() -> Self
Returns a policy that disables freshness and required-component checking entirely.
Only intended for byte-level conformance tests against static RFC 9421 / Cavage fixtures that bake fixed timestamps and minimal component lists into their inputs. Do not use in production.
Sourcepub fn check(
&self,
created_unix: Option<i64>,
expires_unix: Option<i64>,
date_header: Option<&str>,
now: DateTime<Utc>,
) -> Result<(), Error>
pub fn check( &self, created_unix: Option<i64>, expires_unix: Option<i64>, date_header: Option<&str>, now: DateTime<Utc>, ) -> Result<(), Error>
Evaluates the policy against a signature whose created
parameter is created_unix (seconds since epoch), expires
parameter is expires_unix, and whose companion Date header
(if any) contained date_header. Returns Ok when the
signature is fresh, or a specific error otherwise.
§Errors
Returns Error::TimestampMissing when require_timestamp
is on and no source is available, Error::TimestampTooOld
when now - source > max_age, Error::TimestampInFuture
when the source is too far ahead of now, and
Error::TimestampExpired when expires is already in the
past.
Trait Implementations§
Source§impl Clone for VerifyPolicy
impl Clone for VerifyPolicy
Source§fn clone(&self) -> VerifyPolicy
fn clone(&self) -> VerifyPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for VerifyPolicy
Source§impl Debug for VerifyPolicy
impl Debug for VerifyPolicy
Source§impl Default for VerifyPolicy
impl Default for VerifyPolicy
Source§fn default() -> Self
fn default() -> Self
Returns Self::mastodon — the Fediverse-compatible default.
impl Eq for VerifyPolicy
Source§impl PartialEq for VerifyPolicy
impl PartialEq for VerifyPolicy
Source§fn eq(&self, other: &VerifyPolicy) -> bool
fn eq(&self, other: &VerifyPolicy) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for VerifyPolicy
Auto Trait Implementations§
impl Freeze for VerifyPolicy
impl RefUnwindSafe for VerifyPolicy
impl Send for VerifyPolicy
impl Sync for VerifyPolicy
impl Unpin for VerifyPolicy
impl UnsafeUnpin for VerifyPolicy
impl UnwindSafe for VerifyPolicy
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.