pub struct PrefixedApiKey { /* private fields */ }
Expand description
A struct representing the api token generated for, and provided to,
the user. An instance of this struct can be instantiated from a string
provided by the user for further validation, or it can be instantiated
via the new
method while generating a new key to be given to the user.
Implementations§
Source§impl PrefixedApiKey
impl PrefixedApiKey
Sourcepub fn new(
prefix: String,
short_token: String,
long_token: String,
) -> PrefixedApiKey
pub fn new( prefix: String, short_token: String, long_token: String, ) -> PrefixedApiKey
Constructs a new instance of the struct. This is just a wrapper around directly instantiating the struct, and makes no assertions or assumptions about the values provided.
Sourcepub fn short_token(&self) -> &str
pub fn short_token(&self) -> &str
Getter method for accessing the key’s short token
Sourcepub fn long_token(&self) -> &str
pub fn long_token(&self) -> &str
Getter method for accessing the key’s secret long token
Sourcepub fn long_token_hashed<D: Digest + FixedOutputReset>(
&self,
digest: &mut D,
) -> String
pub fn long_token_hashed<D: Digest + FixedOutputReset>( &self, digest: &mut D, ) -> String
Gets the hashed form of the keys secret long token, using the hashing
algorithm provided as digest
. This resets the digest instance while
finalizing so it may be reused afterward.
Sourcepub fn from_string(
pak_string: &str,
) -> Result<PrefixedApiKey, PrefixedApiKeyError>
pub fn from_string( pak_string: &str, ) -> Result<PrefixedApiKey, PrefixedApiKeyError>
Instantiates the struct from the string form of the api token. This
validates that the string has the expected number of parts (deliniated by "_"
),
but otherwise makes no assertions or assumptions about the values.
Trait Implementations§
Source§impl Debug for PrefixedApiKey
A custom implementation of Debug that masks the secret long token that way
the struct can be debug printed without leaking sensitive info into logs
impl Debug for PrefixedApiKey
A custom implementation of Debug that masks the secret long token that way the struct can be debug printed without leaking sensitive info into logs
Source§impl ToString for PrefixedApiKey
A manual implementation of ToString
which does not mask the secret long token.
The Display
trait is explicitely not implemented to avoid accidentally leaking
the long token in logs.
impl ToString for PrefixedApiKey
A manual implementation of ToString
which does not mask the secret long token.
The Display
trait is explicitely not implemented to avoid accidentally leaking
the long token in logs.