"""Shared test constants and utilities."""

from __future__ import annotations

import hashlib
import hmac

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa

test_rsa = rsa.generate_private_key(public_exponent=65537, key_size=2048)

FAKE_RSA_PEM = test_rsa.private_bytes(
    serialization.Encoding.PEM,
    serialization.PrivateFormat.TraditionalOpenSSL,
    serialization.NoEncryption(),
).decode()

WEBHOOK_SECRET = "test-webhook-secret"


def sign_payload(body: bytes, secret: str = WEBHOOK_SECRET) -> str:
    """Compute X-Hub-Signature-256 for a webhook payload."""
    sig = hmac.new(secret.encode(), body, hashlib.sha256).hexdigest()
    return f"sha256={sig}"
