def METHOD_NAME(
    payload: Dict[str, Any],
    private_key: RSAPrivateKey,
    headers: Dict[str, str],
    cert: Optional[Certificate] = None,
) -> str:
    """Encodes a payload into a JWT either using an RSA private key."""
    headers.update({"alg": "RS256"})
    if cert is not None:
        headers.update({"x5t#S256": x5t_s256(cert)})
    return jwt.encode(payload, private_key, algorithm="RS256", headers=headers)