pub struct ApiKey { /* 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 ApiKey
impl ApiKey
pub fn generate( prefix: impl Into<String>, environment: impl Into<Environment>, config: KeyConfig, ) -> Result<Self>
pub fn generate_default( prefix: impl Into<String>, environment: impl Into<Environment>, ) -> Result<Self>
pub fn generate_high_security( prefix: impl Into<String>, environment: impl Into<Environment>, ) -> Result<Self>
pub fn verify( provided_key: impl AsRef<str>, stored_hash: impl AsRef<str>, ) -> Result<bool>
pub fn verify_checksum(key: impl AsRef<str>) -> Result<bool>
Sourcepub fn key(&self) -> &SecureString
pub fn key(&self) -> &SecureString
Returns a reference to the secure API key.
To access the underlying string, use .as_ref() on the returned SecureString:
let key_str: &str = api_key.key().as_ref();§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.
pub fn hash(&self) -> &str
pub fn parse_prefix(key: &SecureString, separator: Separator) -> Result<String>
pub fn parse_environment( key: &SecureString, separator: Separator, ) -> Result<String>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiKey
impl RefUnwindSafe for ApiKey
impl Send for ApiKey
impl Sync for ApiKey
impl Unpin for ApiKey
impl UnwindSafe for ApiKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more