Skip to main content

MemoryStorage

Struct MemoryStorage 

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

The in-memory Storage: a mutexed set of maps. Reference implementation for the trait’s contract (its take_* are atomic by construction) and the store this crate’s own tests run on. Allocates nothing beyond its empty maps until used.

Implementations§

Source§

impl MemoryStorage

Source

pub fn new() -> Self

An empty store.

Trait Implementations§

Source§

impl Default for MemoryStorage

Source§

fn default() -> MemoryStorage

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

impl Storage for MemoryStorage

Source§

async fn compare_and_swap_client( &self, expected: &Client, updated: Client, ) -> Result<bool, StorageError>

The whole operation happens under ONE guard, which is what makes the comparison and the write a single atomic step here. Ok(false) and no write when the record is absent or has moved on; absence is the Storage::delete_client case and it must stay absent.

Source§

async fn compare_and_swap_device_grant( &self, expected: &DeviceGrantState, updated: DeviceGrant, ) -> Result<bool, StorageError>

The whole operation happens under ONE guard, which is what makes it a compare-and-swap rather than a read followed by a hopeful write, and what a single-process host is entitled to expect from the reference implementation.

Both halves of the user-code index contract documented on Storage::put_device_grant are enforced here TOO, restated rather than delegated, because a &mut guard is already held and calling the other method would deadlock. That duplication is a hazard worth naming: an earlier version of this doc claimed the index maintenance was delegated and therefore could not drift, and it had already drifted, because requirement (1), refusing a user code that is live for a DIFFERENT device code, was simply absent. A swap could hand one user code to two grants where a put would have refused. If either method changes, change both.

Source§

async fn compare_and_swap_authorization_code( &self, expected: &AuthorizationCodeState, updated: AuthorizationCodeRecord, ) -> Result<bool, StorageError>

One guard, so the comparison and the write cannot be separated. Absence refuses, which is what keeps a swept or cascaded code from being reinstated.

Available on crate feature consent only.

One guard again, and the comparison is against what find_consent would answer for the PAIR rather than against the consent_id: a withdrawal removes the record the caller read and any replacement has a different id, so comparing ids would miss the interleaving.

Source§

async fn get_client( &self, client_id: &ClientId, ) -> Result<Option<Arc<Client>>, StorageError>

Look up a registered client. Read more
Source§

async fn put_client(&self, client: Client) -> Result<(), StorageError>

Insert or replace a client registration. Read more
Source§

async fn delete_client( &self, client_id: &ClientId, window: RevocationWindow, ) -> Result<bool, StorageError>

Remove a client registration AND everything it was issued, returning whether a registration was actually removed. Read more
Source§

async fn put_device_grant(&self, grant: DeviceGrant) -> Result<(), StorageError>

Insert or replace a device grant, keyed by device_code, maintaining the user-code index. Read more
Source§

async fn get_device_grant( &self, device_code: &str, ) -> Result<Option<DeviceGrant>, StorageError>

Look up a device grant by device code.
Source§

async fn find_device_grant_by_user_code( &self, normalized_user_code: &str, ) -> Result<Option<DeviceGrant>, StorageError>

Look up a device grant by NORMALIZED user code.
Source§

async fn take_device_grant( &self, device_code: &str, ) -> Result<Option<DeviceGrant>, StorageError>

Atomically remove and return a device grant. This is the single-use redemption primitive: under concurrent redemption exactly one caller receives the grant. Read more
Source§

async fn put_authorization_code( &self, record: AuthorizationCodeRecord, ) -> Result<(), StorageError>

Insert or replace an authorization code record, keyed by its code string. Read more
Source§

async fn take_authorization_code( &self, code: &str, ) -> Result<Option<AuthorizationCodeRecord>, StorageError>

Atomically remove and return an authorization code record. This is the single-use redemption primitive for the authorization code grant: under concurrent redemption exactly one caller receives the record and every other caller sees None. Read more
Source§

async fn put_pushed_authorization_request( &self, record: PushedAuthorizationRequest, ) -> Result<WriteOutcome, StorageError>

Available on crate feature par only.
Insert or replace a pushed authorization request (RFC 9126 section 2.2), keyed by its request_uri. Read more
Source§

async fn take_pushed_authorization_request( &self, request_uri: &str, ) -> Result<Option<PushedAuthorizationRequest>, StorageError>

Available on crate feature par only.
Atomically remove and return a pushed authorization request. This is what makes a request_uri single use: RFC 9126 section 4 says a client MUST use one once and section 7.3 asks the server to enforce it rather than trust that, so under concurrent authorization requests exactly one caller receives the record and every other caller sees None. A plain read-then-delete reintroduces the replay this is here to prevent. Read more
Source§

async fn put_token( &self, token: IssuedToken, ) -> Result<WriteOutcome, StorageError>

Persist an issued access token, UNLESS a revocation covers it. Read more
Source§

async fn get_token( &self, access_token: &str, ) -> Result<Option<Arc<IssuedToken>>, StorageError>

Look up an access token (introspection). Read more
Source§

async fn delete_token(&self, access_token: &str) -> Result<(), StorageError>

Remove an access token. Idempotent: removing a token that is already gone is success, as RFC 7009 section 2.2 requires of revocation.
Source§

async fn put_refresh_token( &self, record: RefreshTokenRecord, ) -> Result<WriteOutcome, StorageError>

Persist a refresh token record, UNLESS a revocation covers it. Read more
Source§

async fn get_refresh_token( &self, refresh_token: &str, ) -> Result<Option<Arc<RefreshTokenRecord>>, StorageError>

Look up a refresh token record WITHOUT removing it. Read more
Source§

async fn take_refresh_token( &self, refresh_token: &str, ) -> Result<Option<RefreshTokenRecord>, StorageError>

Atomically remove and return a refresh token record. This is what makes rotation single use: under concurrent refresh exactly one caller wins and every other presentation of the same token is invalid_grant. Read more
Source§

async fn revoke_token_family( &self, family_id: &str, window: RevocationWindow, ) -> Result<u64, StorageError>

Revoke EVERY token, access and refresh, carrying family_id, and return how many records were removed. Read more
Available on crate feature consent only.
Insert or replace a consent record, keyed by its consent_id. Read more
Available on crate feature consent only.
Look up a consent record by its identifier.
Available on crate feature consent only.
The live consent for one (client, subject) pair, if there is one. Read more
Source§

async fn consents_for_subject( &self, subject: &str, ) -> Result<Vec<Arc<ConsentRecord>>, StorageError>

Available on crate feature consent only.
Every consent one resource owner has granted, so a host can show a user what they have approved. Order is not specified; a host that wants one sorts what it gets back.
Available on crate feature consent only.
WITHDRAW a consent: remove the record AND everything issued under it, returning how many records were removed (the consent record itself is not counted). Read more
Source§

async fn claim_replay_id( &self, id: &str, expires_at: SystemTime, ) -> Result<bool, StorageError>

Available on crate features client-assertion or dpop only.
Atomically CLAIM a single-use identifier, returning true when this caller is the first to claim it and false when it has already been claimed. Read more
Source§

async fn sweep_expired(&self, now: SystemTime) -> Result<u64, StorageError>

Remove every record that is dead at now, and return how many were removed. Read more

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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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 = 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.