Struct ddmw_client::auth::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
impl Auth
sourcepub fn have_pass(&self) -> bool
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.
sourcepub fn get_pass(&self) -> Result<String, Error>
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.
sourcepub fn get_token(&self) -> Result<Option<String>, Error>
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.
sourcepub async fn authenticate<C>(
&self,
conn: &mut Framed<C, Codec>
) -> Result<Option<String>, Error>where
C: AsyncRead + AsyncWrite + Unpin,
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:
- If a raw token has been supplied in the
tokenfield, then attempt to authenticate with it and return the results. - If a
token_filehas 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.
- Make sure that an account name and a passphrase has been set. The
passphrase is either set from the
passfield or by loading the contents of the file inpass_file. Return error account name or passphrase can not be acquired. - Authenticate using account name and passphrase. If a
token_filewas specified, then request an authentication token and store it intoken_fileon success. Return error on failure.