Skip to main content

constant_time_str_eq

Function constant_time_str_eq 

Source
pub fn constant_time_str_eq(a: &str, b: &str) -> bool
Expand description

Performs constant-time comparison of two strings.

This is a convenience wrapper around constant_time_eq that works with string slices. Internally, it compares the UTF-8 byte representations.

See constant_time_eq for full documentation on timing attack prevention.

§Example

use fastapi_core::constant_time_str_eq;

let stored_token = "user_api_key_xyz123";
let provided_token = get_token_from_header();

if constant_time_str_eq(stored_token, &provided_token) {
    // Valid token
}