mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
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:
committed by
Tim Abbott
parent
143baa4243
commit
052984bc14
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user