pub struct TokenPolicy { /* private fields */ }Expand description
Per-vendor defaults for the
TokenValidator.
Every field is documented in the
module docs.
The defaults are the values baked into
builtin_token_policies; operators can override per-vendor
with TokenPolicyTable::with_policy.
§Example
use std::time::Duration;
use stygian_charon::token_lifecycle::TokenPolicy;
use stygian_charon::vendor_classifier::VendorId;
let policy = TokenPolicy::default_for(VendorId::Cloudflare);
assert_eq!(policy.default_ttl(), Duration::from_mins(30));
assert!(policy.single_use());Implementations§
Source§impl TokenPolicy
impl TokenPolicy
Sourcepub fn new(
default_ttl: Duration,
max_ttl: Duration,
require_nonce: bool,
single_use: bool,
require_session_binding: bool,
) -> Self
pub fn new( default_ttl: Duration, max_ttl: Duration, require_nonce: bool, single_use: bool, require_session_binding: bool, ) -> Self
Build a TokenPolicy with explicit values. The
constructor clamps default_ttl to max_ttl so a
caller cannot accidentally build a policy whose default
is longer than its maximum.
Sourcepub fn with_default_ttl(self, default_ttl: Duration) -> Self
pub fn with_default_ttl(self, default_ttl: Duration) -> Self
Replace the default TTL. The new value is clamped to
the current max_ttl so the policy invariant
(max_ttl >= default_ttl) is preserved.
§Example
use std::time::Duration;
use stygian_charon::token_lifecycle::TokenPolicy;
let p = TokenPolicy::default_for(stygian_charon::vendor_classifier::VendorId::Cloudflare);
let tighter = p.with_default_ttl(Duration::from_mins(5));
assert_eq!(tighter.default_ttl(), Duration::from_mins(5));Sourcepub fn with_max_ttl(self, max_ttl: Duration) -> Self
pub fn with_max_ttl(self, max_ttl: Duration) -> Self
Replace the maximum TTL.
§Example
use std::time::Duration;
use stygian_charon::token_lifecycle::TokenPolicy;
let p = TokenPolicy::default_for(stygian_charon::vendor_classifier::VendorId::Cloudflare);
let tighter = p.with_max_ttl(Duration::from_mins(20));
assert_eq!(tighter.max_ttl(), Duration::from_mins(20));Sourcepub const fn default_ttl(&self) -> Duration
pub const fn default_ttl(&self) -> Duration
Default TTL baked into this policy.
Sourcepub const fn require_nonce(&self) -> bool
pub const fn require_nonce(&self) -> bool
Whether per-issuance nonce binding is required.
Sourcepub const fn single_use(&self) -> bool
pub const fn single_use(&self) -> bool
Per-vendor default for the single-use flag.
Sourcepub const fn require_session_binding(&self) -> bool
pub const fn require_session_binding(&self) -> bool
Whether sticky-session binding is required.
Sourcepub fn default_for(vendor: VendorId) -> Self
pub fn default_for(vendor: VendorId) -> Self
Per-vendor default policy matching the vendor policy table.
§Example
use std::time::Duration;
use stygian_charon::token_lifecycle::TokenPolicy;
use stygian_charon::vendor_classifier::VendorId;
assert_eq!(TokenPolicy::default_for(VendorId::Cloudflare).default_ttl(), Duration::from_mins(30));
assert_eq!(TokenPolicy::default_for(VendorId::DataDome).default_ttl(), Duration::from_mins(10));
assert_eq!(TokenPolicy::default_for(VendorId::Unknown).default_ttl(), Duration::from_mins(5));Trait Implementations§
Source§impl Clone for TokenPolicy
impl Clone for TokenPolicy
Source§fn clone(&self) -> TokenPolicy
fn clone(&self) -> TokenPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenPolicy
impl Debug for TokenPolicy
Source§impl<'de> Deserialize<'de> for TokenPolicy
impl<'de> Deserialize<'de> for TokenPolicy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for TokenPolicy
impl PartialEq for TokenPolicy
Source§impl Serialize for TokenPolicy
impl Serialize for TokenPolicy
impl Copy for TokenPolicy
impl Eq for TokenPolicy
impl StructuralPartialEq for TokenPolicy
Auto Trait Implementations§
impl Freeze for TokenPolicy
impl RefUnwindSafe for TokenPolicy
impl Send for TokenPolicy
impl Sync for TokenPolicy
impl Unpin for TokenPolicy
impl UnsafeUnpin for TokenPolicy
impl UnwindSafe for TokenPolicy
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.