ApiKey

Struct ApiKey 

Source
pub struct ApiKey<Hash> { /* private fields */ }
Expand description

Represents a generated API key with its hash.

The key field is stored in a SecureString which automatically zeros its memory on drop, preventing potential memory disclosure.

Implementations§

Source§

impl<T> ApiKey<T>

Source

pub fn key(&self) -> &SecureString

Returns a reference to the secure API key.

To access the underlying string, use .expose_secret() on the returned SecureString:

let key_str: &str = api_key.key().expose_secret();
§Security Note

The key is stored in secure memory that is automatically zeroed on drop. Be careful NOT to clone or log the value unnecessarily.

Source§

impl ApiKey<NoHash>

Source

pub fn new(key: SecureString) -> ApiKey<NoHash>

Source

pub fn into_hashed(self, hasher: &KeyHasher) -> Result<ApiKey<Hash>>

Source

pub fn into_key(self) -> SecureString

Source§

impl ApiKey<Hash>

Source

pub fn hash(&self) -> &str

Returns hash. SECURITY: Although it’s safe to store hash, do NOT make unnecessary clones and avoid logging the hash.

Source

pub fn into_key(self) -> SecureString

Trait Implementations§

Source§

impl<Hash: Debug> Debug for ApiKey<Hash>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Hash> Freeze for ApiKey<Hash>
where Hash: Freeze,

§

impl<Hash> RefUnwindSafe for ApiKey<Hash>
where Hash: RefUnwindSafe,

§

impl<Hash> Send for ApiKey<Hash>
where Hash: Send,

§

impl<Hash> Sync for ApiKey<Hash>
where Hash: Sync,

§

impl<Hash> Unpin for ApiKey<Hash>
where Hash: Unpin,

§

impl<Hash> UnwindSafe for ApiKey<Hash>
where Hash: UnwindSafe,

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.