Struct Accounts

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

Independently versioned account store; an empty store is never published.

Implementations§

Source§

impl Accounts

Source

pub fn api_keys(&self, username: &str) -> Result<Vec<&ApiKey>, String>

List one account’s keys in creation order, without secrets or verifiers. Disabled accounts may still be inspected by the local administrator.

Source

pub fn create_api_key( &mut self, username: &str, label: &str, now: u64, ) -> Result<(ApiKey, String), String>

Issue an OS-random id.secret credential and retain only its salted verifier. Both components contain 256 random bits encoded as lowercase hexadecimal. The returned token can be shown once, after the caller successfully saves the store under its writer lock; it cannot be recovered by later reads. Password work must run on a bounded blocking worker for HTTP callers.

Source

pub fn revoke_api_key( &mut self, username: &str, key_id: &str, ) -> Result<(), String>

Revoke exactly one named account’s key, leaving other keys and sessions valid.

Source

pub fn authenticate_api_key(&self, token: &str) -> Option<(&Account, &ApiKey)>

Verify an exact id.secret credential and return its enabled account and key. Well-formed unknown keys perform the same bounded Argon2 work as known keys. HTTP callers must schedule verification on a bounded worker and apply admission/rate limits; these persistent tokens are not sessions.

Source

pub fn api_key_account( &self, key_id: &str, owner: &str, epoch: &str, revision: u64, ) -> Option<&Account>

Recheck a previously authenticated key after reloading the current store. This checks presence, owner, enabled state, epoch and generation without password work. The caller must already have verified the complete token; possessing a public key ID or account metadata is never authentication.

Source§

impl Accounts

Source

pub fn bootstrap( username: &str, password: &str, now: u64, ) -> Result<Accounts, String>

Create the first administrator, retaining the existing local owner.

Source

pub fn all(&self) -> &[Account]

Account metadata in creation order; verifiers remain private.

Source

pub fn epoch(&self) -> &str

Epoch captured by every session; restoring a backup rotates it.

Source

pub fn find(&self, username: &str) -> Option<&Account>

Find a canonical login name, accepting an uppercase spelling.

Source

pub fn authenticate(&self, username: &str, password: &str) -> Option<&Account>

Authenticate without distinguishing missing, disabled or wrong-password accounts. Password work must be scheduled on a bounded blocking worker by HTTP callers.

Source

pub fn session_account( &self, owner: &str, epoch: &str, revision: u64, ) -> Option<&Account>

Validate the owner and generation captured by a session after a reload.

Source

pub fn create( &mut self, username: &str, password: &str, role: Role, now: u64, ) -> Result<(), String>

Add an enabled account with a generated, immutable personal owner.

Source

pub fn set_role( &mut self, username: &str, role: Role, now: u64, ) -> Result<(), String>

Change privileges while retaining at least one enabled administrator.

Source

pub fn set_enabled( &mut self, username: &str, enabled: bool, now: u64, ) -> Result<(), String>

Disable or enable access, preserving every personal record.

Source

pub fn rename( &mut self, username: &str, replacement: &str, now: u64, ) -> Result<(), String>

Rename a login without moving personal data.

Source

pub fn set_password( &mut self, username: &str, password: &str, now: u64, ) -> Result<(), String>

Replace a salted password verifier and invalidate this account’s sessions and API keys.

Source

pub fn revoke(&mut self, username: &str, now: u64) -> Result<(), String>

Revoke one account’s sessions and API keys without changing its password or opinions.

Source

pub fn revoke_all(&mut self) -> Result<(), String>

Invalidate all sessions and API keys, including credentials from before a backup restore.

Trait Implementations§

Source§

impl Clone for Accounts

Source§

fn clone(&self) -> Accounts

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Accounts

Source§

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

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

impl PartialEq for Accounts

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Accounts

Source§

impl StructuralPartialEq for Accounts

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.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

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.

§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,