From ec9d4c367276d4afb92f936117acad4358bf0142 Mon Sep 17 00:00:00 2001 From: shay Date: Sun, 19 Apr 2026 18:47:11 -0400 Subject: [PATCH] db: remove dead _hash_edit_token; convert verify_edit_token to stub _hash_edit_token was only called by verify_edit_token and has no remaining callers in db.py (enroll no longer hashes tokens). Remove it along with the unused 'secrets' and 'hmac' imports. Keep verify_edit_token as a NotImplementedError stub since api.py's require_edit_token decorator still references it. Task 12 will remove both the decorator and this function together when switching to session-based auth. --- generator/src/db.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/generator/src/db.py b/generator/src/db.py index 4436c59..b424427 100644 --- a/generator/src/db.py +++ b/generator/src/db.py @@ -4,10 +4,8 @@ All access goes through this module so a future Postgres swap is local to here. Both DBs are opened with WAL mode. """ import hashlib -import hmac as _hmac import json import os -import secrets import sqlite3 from contextlib import contextmanager from datetime import datetime, timedelta @@ -128,21 +126,15 @@ def init_dbs() -> None: c.commit() -def _hash_edit_token(token: str) -> str: - return hashlib.sha256(token.encode("utf-8")).hexdigest() - - def verify_edit_token(username: str, presented: str) -> bool: - """Constant-time check of the caller's edit token against the stored hash.""" - if not username or not presented: - return False - with _settings_conn() as c: - row = c.execute( - "SELECT edit_token_hash FROM users WHERE username=?", (username,) - ).fetchone() - if row is None or not row["edit_token_hash"]: - return False - return _hmac.compare_digest(row["edit_token_hash"], _hash_edit_token(presented)) + """Constant-time check of the caller's edit token against the stored hash. + + DEPRECATED: This function is dead code as of Task 5 (edit tokens are no longer + hashed during enrollment). It remains here temporarily while api.py's + require_edit_token decorator is still being used. Task 12 will remove both + this function and the decorator consumer in api.py. + """ + raise NotImplementedError("verify_edit_token is deprecated; will be removed in Task 12") def settings_hash(settings: dict) -> str: