mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
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:
+8
-16
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user