semantics

This commit is contained in:
2026-05-26 09:30:41 +03:00
parent 1e7bcecaea
commit 9ffa8af1dc
623 changed files with 28045 additions and 26557 deletions

View File

@@ -1,8 +1,8 @@
# #region APIKeyUtilities [C:2] [TYPE Module] [SEMANTICS auth, api_key, crypto, generation]
# @BRIEF API key generation and hashing utilities for service-to-service authentication.
# @LAYER Core
# @RELATION DEPENDS_ON -> [hashlib]
# @RELATION DEPENDS_ON -> [secrets]
# @RELATION DEPENDS_ON -> [EXT:Python:hashlib]
# @RELATION DEPENDS_ON -> [EXT:Python:secrets]
# @INVARIANT generate_api_key() always returns (raw_key, prefix, key_hash) where prefix is "ssk_" + 7 chars.
# @INVARIANT hash_api_key() produces SHA-256 hex digest for lookup and storage.
@@ -14,8 +14,8 @@ import secrets
# @BRIEF Generate a new API key in ssk_ format with SHA-256 hash.
# @POST Returns (raw_key, prefix, key_hash) — raw_key shown ONCE to caller, never stored.
# @SIDE_EFFECT Uses secrets.token_urlsafe(32) for cryptographic randomness.
# @RELATION DEPENDS_ON -> [secrets.token_urlsafe]
# @RELATION DEPENDS_ON -> [hashlib.sha256]
# @RELATION DEPENDS_ON -> [EXT:Python:secrets.token_urlsafe]
# @RELATION DEPENDS_ON -> [EXT:Python:hashlib.sha256]
def generate_api_key() -> tuple[str, str, str]:
"""Generate a new API key.
@@ -37,7 +37,7 @@ def generate_api_key() -> tuple[str, str, str]:
# @BRIEF Hash an API key string to SHA-256 hex digest for lookup.
# @PRE raw_key is a non-empty string.
# @POST Returns 64-character hex digest.
# @RELATION DEPENDS_ON -> [hashlib.sha256]
# @RELATION DEPENDS_ON -> [EXT:Python:hashlib.sha256]
def hash_api_key(raw_key: str) -> str:
"""Hash an API key using SHA-256.