pub mod cookie;
pub mod extractor;
pub mod jwt;
pub mod password;
pub use cookie::AUTH_COOKIE_NAME;
pub use extractor::{AuthUser, JwtSecret, OptionalAuth};
pub use jwt::Claims;
pub fn sha256_hex(input: &str) -> String {
use sha2::{Digest, Sha256};
let hash = Sha256::digest(input.as_bytes());
hash.iter().map(|b| format!("{b:02x}")).collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sha256_hex_known_digest() {
let expected = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824";
assert_eq!(sha256_hex("hello"), expected);
}
#[test]
fn sha256_hex_empty_input() {
let expected = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
assert_eq!(sha256_hex(""), expected);
}
#[test]
fn sha256_hex_returns_lowercase_hex() {
let result = sha256_hex("test");
assert_eq!(result.len(), 64);
assert!(result.chars().all(|c| c.is_ascii_hexdigit()));
assert!(result.chars().all(|c| !c.is_ascii_uppercase()));
}
}