Skip to main content

CpskValidator

Struct CpskValidator 

Source
pub struct CpskValidator { /* private fields */ }
Expand description

Capability Pre-Shared Key (CPSK) validator

Stores tokens in memory with their associated scopes. Tokens have the format: cpsk_<base62-random-32-chars>

Implementations§

Source§

impl CpskValidator

Source

pub const PREFIX: &'static str = "cpsk_"

Token prefix for CPSK tokens

Source

pub fn new() -> Self

Create a new empty CPSK validator

Source

pub fn with_default_ttl(ttl: Duration) -> Self

Create a new CPSK validator with a default token TTL. Tokens registered without an explicit expiry will expire after this duration. The relay uses 24h by default to prevent indefinitely-valid tokens (Phase 1.2).

Source

pub fn register(&self, token: String, info: TokenInfo)

Register a token with the given scopes. If the token has no expiry and a default TTL is configured, the TTL is applied.

Source

pub fn revoke(&self, token: &str) -> bool

Revoke a token

Source

pub fn exists(&self, token: &str) -> bool

Check if a token exists (without full validation)

Source

pub fn len(&self) -> usize

Get the number of registered tokens

Source

pub fn is_empty(&self) -> bool

Check if the validator has no tokens

Source

pub fn list_tokens(&self) -> Vec<String>

List all token IDs (for admin purposes)

Source

pub fn generate_token() -> String

Generate a new CPSK token string using cryptographically secure randomness

Trait Implementations§

Source§

impl Default for CpskValidator

Source§

fn default() -> Self

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

impl TokenValidator for CpskValidator

Source§

fn validate(&self, token: &str) -> ValidationResult

Validate a token and return token information if valid
Source§

fn name(&self) -> &str

Get the name of this validator (for logging)
Source§

fn as_any(&self) -> &dyn Any

Returns self as Any for downcasting

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.