Struct PrefixedApiKey

Source
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

Source

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.

Source

pub fn prefix(&self) -> &str

Getter method for accessing the key’s prefix

Source

pub fn short_token(&self) -> &str

Getter method for accessing the key’s short token

Source

pub fn long_token(&self) -> &str

Getter method for accessing the key’s secret long token

Source

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.

Source

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

Source§

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

Formats the value using the given formatter. Read more
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.

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl TryInto<PrefixedApiKey> for &str

Source§

type Error = PrefixedApiKeyError

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<PrefixedApiKey, Self::Error>

Performs the conversion.

Auto Trait Implementations§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V