utils: Remove make_safe_digest wrapper.

It’s unclear what was supposed to be “safe” about this wrapper.  The
hashlib API is fine without it, and we don’t want to encourage further
use of SHA-1.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-07-18 15:44:51 -07:00
committed by Tim Abbott
parent 143baa4243
commit 052984bc14
7 changed files with 22 additions and 35 deletions

View File

@@ -1,23 +1,10 @@
import hashlib
import re
import secrets
from typing import TYPE_CHECKING, Callable, List, Optional, TypeVar
if TYPE_CHECKING:
from hashlib import _Hash
from typing import Callable, List, Optional, TypeVar
T = TypeVar("T")
def make_safe_digest(string: str, hash_func: "Callable[[bytes], _Hash]" = hashlib.sha1) -> str:
"""
return a hex digest of `string`.
"""
# hashlib.sha1, md5, etc. expect bytes, so non-ASCII strings must
# be encoded.
return hash_func(string.encode()).hexdigest()
def generate_api_key() -> str:
api_key = ""
while len(api_key) < 32: