o
    £ý¸iÞ  ã                   @  s6   d Z ddlmZ ddlZddlmZ G dd„ dƒZdS )zÜRequest signature validation helpers.

The implementation is intentionally light. It provides a stable interface for
future HMAC or signed webhook validation without imposing a specific auth
scheme on the existing apps.
é    )ÚannotationsN)Úsha256c                   @  s   e Zd ZdZdd	d
„ZdS )ÚSignatureValidatorz=Validate signed requests using a shared-secret HMAC contract.ÚpayloadÚbytesÚprovided_signatureú
str | NoneÚsecretÚreturnÚboolc                C  s8   |r|r|sdS t  | d¡|t¡ ¡ }t  || ¡ ¡S )zàReturn ``True`` when the provided signature matches the payload.

        Empty signatures are treated as invalid so callers can decide whether
        the endpoint requires signatures or supports anonymous traffic.
        Fzutf-8)ÚhmacÚnewÚencoder   Ú	hexdigestÚcompare_digestÚstrip)Úselfr   r   r	   Úexpected© r   ú'platform/gateway/signature_validator.pyÚvalidate   s   zSignatureValidator.validateN)r   r   r   r   r	   r   r
   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   )r   Ú
__future__r   r   Úhashlibr   r   r   r   r   r   Ú<module>   s
    