pub struct RequestPolicy { /* private fields */ }Expand description
Limits applied by verify_request.
The clock-skew window can be narrowed below the profile’s ±60 seconds but never widened past it, so every policy enforces at least the freshness the Stratum signed-request profile fixes.
§Examples
use std::time::Duration;
use stratum_node_core::{RequestPolicy, RequestPolicyError};
let policy = RequestPolicy::new().with_max_clock_skew(Duration::from_secs(30))?;
assert_eq!(policy.max_clock_skew(), Duration::from_secs(30));
assert_eq!(policy.max_token_bytes(), RequestPolicy::DEFAULT_MAX_TOKEN_BYTES);
let wider = RequestPolicy::new().with_max_clock_skew(Duration::from_secs(61));
assert!(matches!(wider, Err(RequestPolicyError::ClockSkewTooWide { .. })));Implementations§
Source§impl RequestPolicy
impl RequestPolicy
Sourcepub const DEFAULT_MAX_CLOCK_SKEW: Duration
pub const DEFAULT_MAX_CLOCK_SKEW: Duration
The default and largest clock skew allowed on either side of now:
60 seconds, the window the Stratum signed-request profile fixes.
Sourcepub const DEFAULT_MAX_TOKEN_BYTES: usize
pub const DEFAULT_MAX_TOKEN_BYTES: usize
The default largest Authorization header accepted: 64 KiB, far
above a three-tag request event and small enough to bound the work
spent on an unauthenticated header.
Sourcepub const fn with_max_clock_skew(
self,
skew: Duration,
) -> Result<Self, RequestPolicyError>
pub const fn with_max_clock_skew( self, skew: Duration, ) -> Result<Self, RequestPolicyError>
Narrows the clock skew allowed on either side of now.
skew may be anything up to and including
DEFAULT_MAX_CLOCK_SKEW. The
comparison is exact, so 60.5 seconds is refused. Within the limit,
sub-second precision is ignored when verifying, because created_at
is in whole seconds.
§Errors
Returns RequestPolicyError::ClockSkewTooWide when skew is longer
than DEFAULT_MAX_CLOCK_SKEW. The
policy is Copy, so the caller still holds the unchanged original.
Sourcepub const fn with_max_token_bytes(self, bytes: usize) -> Self
pub const fn with_max_token_bytes(self, bytes: usize) -> Self
Sets the largest Authorization header length accepted, in bytes.
Sourcepub const fn max_clock_skew(&self) -> Duration
pub const fn max_clock_skew(&self) -> Duration
Returns the clock skew allowed on either side of now.
Sourcepub const fn max_token_bytes(&self) -> usize
pub const fn max_token_bytes(&self) -> usize
Returns the largest Authorization header length accepted, in bytes.