Skip to main content

SecureCompare

Trait SecureCompare 

Source
pub trait SecureCompare {
    // Required methods
    fn secure_eq(&self, other: &str) -> bool;
    fn secure_eq_bytes(&self, other: &[u8]) -> bool;
}
Expand description

Extension trait for constant-time equality comparison on BearerToken.

Provides a method to securely compare bearer tokens without leaking timing information about where tokens differ.

§Example

use fastapi_core::{BearerToken, SecureCompare};

async fn validate_token(token: BearerToken) -> bool {
    let expected = "valid_api_key_12345";
    token.secure_eq(expected)
}

Required Methods§

Source

fn secure_eq(&self, other: &str) -> bool

Compares this value with another using constant-time comparison.

Returns true if the values are equal, false otherwise. The comparison time is independent of where (or if) the values differ.

Source

fn secure_eq_bytes(&self, other: &[u8]) -> bool

Compares this value with a byte slice using constant-time comparison.

Implementations on Foreign Types§

Source§

impl SecureCompare for str

Source§

fn secure_eq(&self, other: &str) -> bool

Source§

fn secure_eq_bytes(&self, other: &[u8]) -> bool

Source§

impl SecureCompare for String

Source§

fn secure_eq(&self, other: &str) -> bool

Source§

fn secure_eq_bytes(&self, other: &[u8]) -> bool

Source§

impl SecureCompare for Vec<u8>

Source§

fn secure_eq(&self, other: &str) -> bool

Source§

fn secure_eq_bytes(&self, other: &[u8]) -> bool

Source§

impl SecureCompare for [u8]

Source§

fn secure_eq(&self, other: &str) -> bool

Source§

fn secure_eq_bytes(&self, other: &[u8]) -> bool

Source§

impl<const N: usize> SecureCompare for [u8; N]

Source§

fn secure_eq(&self, other: &str) -> bool

Source§

fn secure_eq_bytes(&self, other: &[u8]) -> bool

Implementors§

Source§

impl SecureCompare for ApiKeyCookie

Implement SecureCompare for timing-safe API key validation.

Source§

impl SecureCompare for ApiKeyHeader

Implement SecureCompare for timing-safe API key validation.

Source§

impl SecureCompare for ApiKeyQuery

Implement SecureCompare for timing-safe API key validation.

Source§

impl SecureCompare for BearerToken