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.
This commit is contained in:
shay
2026-04-19 18:47:11 -04:00
parent 22483aea19
commit ec9d4c3672
+8 -16
View File
@@ -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. Both DBs are opened with WAL mode.
""" """
import hashlib import hashlib
import hmac as _hmac
import json import json
import os import os
import secrets
import sqlite3 import sqlite3
from contextlib import contextmanager from contextlib import contextmanager
from datetime import datetime, timedelta from datetime import datetime, timedelta
@@ -128,21 +126,15 @@ def init_dbs() -> None:
c.commit() 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: def verify_edit_token(username: str, presented: str) -> bool:
"""Constant-time check of the caller's edit token against the stored hash.""" """Constant-time check of the caller's edit token against the stored hash.
if not username or not presented:
return False DEPRECATED: This function is dead code as of Task 5 (edit tokens are no longer
with _settings_conn() as c: hashed during enrollment). It remains here temporarily while api.py's
row = c.execute( require_edit_token decorator is still being used. Task 12 will remove both
"SELECT edit_token_hash FROM users WHERE username=?", (username,) this function and the decorator consumer in api.py.
).fetchone() """
if row is None or not row["edit_token_hash"]: raise NotImplementedError("verify_edit_token is deprecated; will be removed in Task 12")
return False
return _hmac.compare_digest(row["edit_token_hash"], _hash_edit_token(presented))
def settings_hash(settings: dict) -> str: def settings_hash(settings: dict) -> str: