Skip to content

Commit

Permalink
Fix compat with werkzeug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Aug 9, 2022
1 parent 1b73541 commit 8ba8016
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions jazzband/hooks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import hmac
import json
import uuid
from datetime import datetime

from flask import current_app
from flask_hookserver import Hooks
import werkzeug.security

from .db import redis
from .members.models import User
Expand All @@ -13,6 +15,26 @@
hooks = Hooks()


def safe_str_cmp(a: str, b: str) -> bool:
"""This function compares strings in somewhat constant time. This
requires that the length of at least one string is known in advance.
Returns `True` if the two strings are equal, or `False` if they are not.
"""

if isinstance(a, str):
a = a.encode("utf-8") # type: ignore

if isinstance(b, str):
b = b.encode("utf-8") # type: ignore

return hmac.compare_digest(a, b)


# Monkeypatch hookserver to fix werkzeug compatibility.
werkzeug.security.safe_str_cmp = safe_str_cmp


@hooks.hook("ping")
def ping(data, guid):
return "pong"
Expand Down

0 comments on commit 8ba8016

Please sign in to comment.