Skip to main content

AuthManager

Struct AuthManager 

Source
pub struct AuthManager<S, A, const SESSION_LEN: usize = DEFAULT_SESSION_LEN, const HASH_LEN: usize = DEFAULT_HASH_LEN, const PEPPER_LEN: usize = DEFAULT_PEPPER_LEN, const SALT_LEN: usize = DEFAULT_SALT_LEN, const ACCOUNT_LOCK_SHARDS: usize = 4096>
where S: KVTrait<[u8; SESSION_LEN], SessionValue<SESSION_LEN>> + Send + Sync, A: KVTrait<str, AccountValue<SALT_LEN, HASH_LEN, SESSION_LEN>> + Send + Sync,
{ pub sessions: S, pub accounts: A, pub session_timeout: Duration, pub account_timeout: Duration, pub password_hasher: Argon2<'static>, pub pepper: [u8; PEPPER_LEN], /* private fields */ }
Expand description

Main AuthManager

  • sessions はキャッシュ扱い。必要なら verify して primary_account を落とす。
  • account 側が正。session はキャッシュ更新

Fields§

§sessions: S§accounts: A§session_timeout: Duration§account_timeout: Duration§password_hasher: Argon2<'static>§pepper: [u8; PEPPER_LEN]

Implementations§

Source§

impl<S, A, const SESSION_LEN: usize, const HASH_LEN: usize, const PEPPER_LEN: usize, const SALT_LEN: usize, const ACCOUNT_LOCK_SHARDS: usize> AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>
where S: KVTrait<[u8; SESSION_LEN], SessionValue<SESSION_LEN>> + Send + Sync, A: KVTrait<str, AccountValue<SALT_LEN, HASH_LEN, SESSION_LEN>> + Send + Sync,

Source

pub fn new( sessions: S, accounts: A, session_timeout: Duration, account_timeout: Duration, hash_config: HashConfig<PEPPER_LEN>, ) -> Self

Source

pub fn create_session(&self) -> [u8; SESSION_LEN]

session_id はランダム生成。衝突したらリトライ。

Source

pub fn delete_session(&self, session_id: &[u8; SESSION_LEN]) -> bool

Source

pub fn get_and_verify_session( &self, session_id: &[u8; SESSION_LEN], ) -> Option<SessionValue<SESSION_LEN>>

ガード入り Noneならcreate sessionするなりするとよい

Source

pub fn update_or_gc_session( &self, session_id: &[u8; SESSION_LEN], ) -> Option<SessionValue<SESSION_LEN>>

Source

pub fn gc_sessions( &self, session_id: &[u8; SESSION_LEN], ) -> Option<SessionValue<SESSION_LEN>>

Source

pub fn set_primary_account( &self, session_id: &[u8; SESSION_LEN], username: &str, ) -> bool

Source

pub fn add_account(&self, username: &str, password: &str)

Source

pub fn delete_account(&self, username: &str) -> bool

Source

pub fn get_account( &self, username: &str, ) -> Option<AccountValue<SALT_LEN, HASH_LEN, SESSION_LEN>>

Source

pub fn auth_login( &self, session_id: &[u8; SESSION_LEN], username: &str, password: &str, ) -> bool

Source

pub fn auth_verify( &self, session_id: &[u8; SESSION_LEN], username: &str, ) -> bool

認可

Source

pub fn auth_logout( &self, session_id: &[u8; SESSION_LEN], username: &str, ) -> bool

logout は account 側だけ更新

Auto Trait Implementations§

§

impl<S, A, const SESSION_LEN: usize = DEFAULT_SESSION_LEN, const HASH_LEN: usize = DEFAULT_HASH_LEN, const PEPPER_LEN: usize = DEFAULT_PEPPER_LEN, const SALT_LEN: usize = DEFAULT_SALT_LEN, const ACCOUNT_LOCK_SHARDS: usize = 4096> !Freeze for AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>

§

impl<S, A, const SESSION_LEN: usize = DEFAULT_SESSION_LEN, const HASH_LEN: usize = DEFAULT_HASH_LEN, const PEPPER_LEN: usize = DEFAULT_PEPPER_LEN, const SALT_LEN: usize = DEFAULT_SALT_LEN, const ACCOUNT_LOCK_SHARDS: usize = 4096> !RefUnwindSafe for AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>

§

impl<S, A, const SESSION_LEN: usize, const HASH_LEN: usize, const PEPPER_LEN: usize, const SALT_LEN: usize, const ACCOUNT_LOCK_SHARDS: usize> Send for AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>

§

impl<S, A, const SESSION_LEN: usize, const HASH_LEN: usize, const PEPPER_LEN: usize, const SALT_LEN: usize, const ACCOUNT_LOCK_SHARDS: usize> Sync for AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>

§

impl<S, A, const SESSION_LEN: usize, const HASH_LEN: usize, const PEPPER_LEN: usize, const SALT_LEN: usize, const ACCOUNT_LOCK_SHARDS: usize> Unpin for AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>
where S: Unpin, A: Unpin,

§

impl<S, A, const SESSION_LEN: usize, const HASH_LEN: usize, const PEPPER_LEN: usize, const SALT_LEN: usize, const ACCOUNT_LOCK_SHARDS: usize> UnsafeUnpin for AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>
where S: UnsafeUnpin, A: UnsafeUnpin,

§

impl<S, A, const SESSION_LEN: usize, const HASH_LEN: usize, const PEPPER_LEN: usize, const SALT_LEN: usize, const ACCOUNT_LOCK_SHARDS: usize> UnwindSafe for AuthManager<S, A, SESSION_LEN, HASH_LEN, PEPPER_LEN, SALT_LEN, ACCOUNT_LOCK_SHARDS>
where S: UnwindSafe, A: UnwindSafe,

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