refactor: simplify hash_token using format macro

Replace manual hex encoding loop with `format!("{:x}", Sha256::digest(...))`,
which is more idiomatic and concise.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
fettpl 2026-02-15 00:28:04 +01:00
parent b3bfbaff4a
commit 23048d10ac

View file

@ -195,13 +195,7 @@ fn generate_token() -> String {
/// SHA-256 hash a bearer token for storage. Returns lowercase hex.
fn hash_token(token: &str) -> String {
let digest = Sha256::digest(token.as_bytes());
let mut hex = String::with_capacity(64);
for b in digest {
use std::fmt::Write;
let _ = write!(hex, "{b:02x}");
}
hex
format!("{:x}", Sha256::digest(token.as_bytes()))
}
/// Check if a stored value looks like a SHA-256 hash (64 hex chars)