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§
Sourcefn secure_eq(&self, other: &str) -> bool
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.
Sourcefn secure_eq_bytes(&self, other: &[u8]) -> bool
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
impl SecureCompare for str
Source§impl SecureCompare for String
impl SecureCompare for String
Source§impl SecureCompare for Vec<u8>
impl SecureCompare for Vec<u8>
Source§impl SecureCompare for [u8]
impl SecureCompare for [u8]
Implementors§
impl SecureCompare for ApiKeyCookie
Implement SecureCompare for timing-safe API key validation.
impl SecureCompare for ApiKeyHeader
Implement SecureCompare for timing-safe API key validation.
impl SecureCompare for ApiKeyQuery
Implement SecureCompare for timing-safe API key validation.