amduat-api/notes/sid_hashers.py
2026-01-17 00:19:49 +01:00

40 lines
976 B
Python

# sid_hashers.py
from abc import ABC, abstractmethod
import hashlib
# ---------------------------------------------------------------------
# Structural hash strategy interface
# ---------------------------------------------------------------------
class StructureHashStrategy(ABC):
"""
Abstract interface for derivation / structural hashers.
"""
@abstractmethod
def hash_struct(self, payload: bytes) -> str:
"""
Hash a byte payload deterministically and return hex digest.
"""
pass
# ---------------------------------------------------------------------
# SHA-256 default implementation
# ---------------------------------------------------------------------
class SHA256SIDHash(StructureHashStrategy):
"""
Default SHA-256 SID hasher.
"""
name = "sha256.sid.v1"
def hash_struct(self, payload: bytes) -> str:
h = hashlib.sha256()
h.update(payload)
return h.hexdigest()