Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /nfraxlab_svc-infra /src /svc_infra /webhooks /signing.py
| from __future__ import annotations | |
| import hashlib | |
| import hmac | |
| import json | |
| import logging | |
| from collections.abc import Iterable | |
| logger = logging.getLogger(__name__) | |
| def canonical_body(payload: dict) -> bytes: | |
| return json.dumps(payload, separators=(",", ":"), sort_keys=True).encode() | |
| def sign(secret: str, payload: dict) -> str: | |
| body = canonical_body(payload) | |
| return hmac.new(secret.encode(), body, hashlib.sha256).hexdigest() | |
| def verify(secret: str, payload: dict, signature: str) -> bool: | |
| expected = sign(secret, payload) | |
| try: | |
| return hmac.compare_digest(expected, signature) | |
| except Exception as e: | |
| logger.warning("Webhook signature verification failed: %s", e) | |
| return False | |
| def verify_any(secrets: Iterable[str], payload: dict, signature: str) -> bool: | |
| for s in secrets: | |
| if verify(s, payload, signature): | |
| return True | |
| return False | |
Xet Storage Details
- Size:
- 916 Bytes
- Xet hash:
- 5594051de14e900f06f5e44b4993f4b6408c5eade7ef97fbe2085edc950dd592
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.