Struct Auth

Source
pub struct Auth {
    pub name: Option<String>,
    pub pass_file: Option<String>,
    pub pass: Option<String>,
    pub token_file: Option<String>,
    pub token: Option<String>,
}
Expand description

Authentication context used to signal how to authenticate a connection.

Fields§

§name: Option<String>

Account name used to authenticate.

§pass_file: Option<String>

Load raw account passphrase from the specified filename.

§pass: Option<String>

Raw account passphrase to authenticate with. Only used if name has been set.

§token_file: Option<String>

Use the specified file for authentication token storage.

§token: Option<String>

Authentication token.

Implementations§

Source§

impl Auth

Source

pub fn have_pass(&self) -> bool

Return true if there’s either a raw passphrase set in pass or a passphrase file has beeen set in pass_file. This function does not validate if the passphrase file exists or is accessible.

Source

pub fn get_pass(&self) -> Result<String, Error>

Get passphrase.

Return the raw pass field if set. Otherwise, load the pass_file if set, and return error if the passphrase could not be loaded from the file.

If neither pass nor pass_file have been set, return an error.

Source

pub fn get_token(&self) -> Result<Option<String>, Error>

Get authentication token.

Return the raw token field if set. Otherwise, check if token_file is set. If it is, then attempt to load the token from it. If the file does not exist, then:

  • Return Ok(None) if account name and pass(file) have been set.
  • Return error if account name has not been set.
Source

pub async fn authenticate<C>( &self, conn: &mut Framed<C, Codec>, ) -> Result<Option<String>, Error>
where C: AsyncRead + AsyncWrite + Unpin,

Helper function for authenticating a connection.

Authenticates the connection specified in conn, using the credentials stored in the Auth buffer using the following logic:

  1. If a raw token has been supplied in the token field, then attempt to authenticate with it and return the results.
  2. If a token_file has been been set, then:
    • If the file exists, try to load the authentication token, authenticate with it, and return the results.
    • If the file does not exist, then:
      • If account name and/or passphrase have not been set, then return error.
      • If account name and passphrase have been set, then continue.
  3. Make sure that an account name and a passphrase has been set. The passphrase is either set from the pass field or by loading the contents of the file in pass_file. Return error account name or passphrase can not be acquired.
  4. Authenticate using account name and passphrase. If a token_file was specified, then request an authentication token and store it in token_file on success. Return error on failure.

Trait Implementations§

Source§

impl Clone for Auth

Source§

fn clone(&self) -> Auth

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 Auth

Source§

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

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

impl Default for Auth

Source§

fn default() -> Auth

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

impl<'de> Deserialize<'de> for Auth

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

§

impl Freeze for Auth

§

impl RefUnwindSafe for Auth

§

impl Send for Auth

§

impl Sync for Auth

§

impl Unpin for Auth

§

impl UnwindSafe for Auth

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.

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,