Skip to main content

RequestPolicy

Struct RequestPolicy 

Source
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

Source

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.

Source

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.

Source

pub const fn new() -> Self

Returns the default policy.

Source

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.

Source

pub const fn with_max_token_bytes(self, bytes: usize) -> Self

Sets the largest Authorization header length accepted, in bytes.

Source

pub const fn max_clock_skew(&self) -> Duration

Returns the clock skew allowed on either side of now.

Source

pub const fn max_token_bytes(&self) -> usize

Returns the largest Authorization header length accepted, in bytes.

Trait Implementations§

Source§

impl Clone for RequestPolicy

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 Copy for RequestPolicy

Source§

impl Debug for RequestPolicy

Source§

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

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

impl Default for RequestPolicy

Source§

fn default() -> Self

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

impl Eq for RequestPolicy

Source§

impl Hash for RequestPolicy

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for RequestPolicy

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RequestPolicy

Auto Trait Implementations§

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.