Skip to main content

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 sha256;
6pub mod x509;
7
8/// Compares in time independent of where the inputs first differ, so response
9/// timing doesn't reveal how much of a guessed token was right.
10pub(crate) fn constant_time_eq(a: &[u8], b: &[u8]) -> bool {
11    if a.len() != b.len() {
12        return false;
13    }
14    a.iter().zip(b).fold(0u8, |diff, (x, y)| diff | (x ^ y)) == 0
15}
16
17pub trait New {
18    fn new() -> Self;
19}