pub struct SafeBox { /* private fields */ }
Expand description
Interface to the password database.
Implementations§
Source§impl SafeBox
impl SafeBox
Sourcepub async fn new(p: impl AsRef<Path>) -> Result<Self, Error>
pub async fn new(p: impl AsRef<Path>) -> Result<Self, Error>
Open an SQLite connection with specified database file and create a SafeBox
.
§Example
use safe_box::SafeBox;
let safe = SafeBox::new("secure.db").await.unwrap();
Sourcepub fn issue_token(&self, user: &str) -> String
pub fn issue_token(&self, user: &str) -> String
Issue a token to the speficied user.
Sourcepub fn invalidate_token(&self, token: &str)
pub fn invalidate_token(&self, token: &str)
Invalidate a token.
Sourcepub fn invalidate_user_token(&self, user: &str)
pub fn invalidate_user_token(&self, user: &str)
Invalidate all tokens related to specified user.
Sourcepub fn expire_token(&self, duration: Duration)
pub fn expire_token(&self, duration: Duration)
Make all tokens older than duration
expire.
Sourcepub async fn create(&self, user: &str, pass: &str) -> Result<(), Error>
pub async fn create(&self, user: &str, pass: &str) -> Result<(), Error>
Create new user entry with user
name and pass
word.
Sourcepub async fn verify(&self, user: &str, pass: &str) -> Result<bool, Error>
pub async fn verify(&self, user: &str, pass: &str) -> Result<bool, Error>
Verify the provided user
name and pass
word.
Return a new token if successful.
Sourcepub fn verify_token(&self, token: &str) -> Option<String>
pub fn verify_token(&self, token: &str) -> Option<String>
Verify the provided token
.
Returns the user it belongs to if valid.
Auto Trait Implementations§
impl !Freeze for SafeBox
impl !RefUnwindSafe for SafeBox
impl Send for SafeBox
impl Sync for SafeBox
impl Unpin for SafeBox
impl !UnwindSafe for SafeBox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more