Skip to main content

RefreshRotator

Struct RefreshRotator 

Source
pub struct RefreshRotator<'s, S: RefreshStore + ?Sized> { /* private fields */ }
Expand description

Mint and rotate refresh tokens against a RefreshStore.

Holds a borrow of the store; the rotator itself is cheap to construct per request. ttl_seconds is the lifetime applied to every freshly minted token (root and successor).

Implementations§

Source§

impl<'s, S: RefreshStore + ?Sized> RefreshRotator<'s, S>

Source

pub fn new(store: &'s S, ttl_seconds: i64) -> Self

Source

pub fn ttl_seconds(&self) -> i64

Source

pub async fn mint_root( &self, user_id: UserId, device_id: DeviceId, now: i64, ) -> Result<Rotated, RefreshError>

Start a fresh chain. Returns the root token + persisted record.

Source

pub async fn rotate( &self, presented: &str, now: i64, ) -> Result<Rotated, RefreshError>

Rotate presented → fresh successor.

Failure modes (in priority order):

Equivalent to check followed by commit; split callers use the gap between the two to refuse a rotation without spending the token.

Source

pub async fn check( &self, presented: &str, now: i64, ) -> Result<LiveRefresh, RefreshError>

Phase one of a rotation: look presented up and prove it is spendable, without spending it.

Every failure of rotate except a lost consume race surfaces here — including replay, whose chain revocation happens here as a side effect. A successful check mutates nothing, so a caller that decides not to commit (R730: no device binding to mint with) leaves the chain exactly as it found it.

Source

pub async fn commit( &self, live: LiveRefresh, now: i64, ) -> Result<Rotated, RefreshError>

Phase two of a rotation: spend the checked token and issue its successor on the same chain.

The LiveRefresh argument can only come from check, so a commit is always preceded by the full validity check. The check result is a snapshot, though, and the consume below is the real gate.

Source

pub async fn revoke_chain(&self, chain_id: &str) -> Result<(), RefreshError>

Revoke every token in chain_id. Idempotent. Use on logout or device-revoke flows.

Auto Trait Implementations§

§

impl<'s, S> Freeze for RefreshRotator<'s, S>
where &'s S: Freeze, S: ?Sized,

§

impl<'s, S> RefUnwindSafe for RefreshRotator<'s, S>

§

impl<'s, S> Send for RefreshRotator<'s, S>
where &'s S: Send, S: ?Sized,

§

impl<'s, S> Sync for RefreshRotator<'s, S>
where &'s S: Sync, S: ?Sized,

§

impl<'s, S> Unpin for RefreshRotator<'s, S>
where &'s S: Unpin, S: ?Sized,

§

impl<'s, S> UnsafeUnpin for RefreshRotator<'s, S>
where &'s S: UnsafeUnpin, S: ?Sized,

§

impl<'s, S> UnwindSafe for RefreshRotator<'s, S>
where &'s S: UnwindSafe, S: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more