rust_web_server/core/mod.rs
1//! Small shared utilities: [`base64`], [`sha256`] (SHA-256, HMAC-SHA256) and the [`New`] trait (a constructor
2//! used across the crate, much like `Default`).
3
4pub mod base64;
5pub mod json;
6pub mod sha256;
7pub mod x509;
8
9/// Compares in time independent of where the inputs first differ, so response
10/// timing doesn't reveal how much of a guessed token was right.
11pub(crate) fn constant_time_eq(a: &[u8], b: &[u8]) -> bool {
12 if a.len() != b.len() {
13 return false;
14 }
15 a.iter().zip(b).fold(0u8, |diff, (x, y)| diff | (x ^ y)) == 0
16}
17
18pub trait New {
19 fn new() -> Self;
20}