fix 3.11 python

This commit is contained in:
Mylloon 2022-10-27 17:46:33 +02:00
parent df488e667b
commit bca224601a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,4 +1,5 @@
from hashlib import sha256
from sys import set_int_max_str_digits, version_info
BYTEORDER = "big"
@ -16,10 +17,12 @@ def exist(path: str) -> bool:
def int_to_bytes(data: int) -> bytes:
"""Transforme un int en bytes"""
"""Convert int to bytes"""
return data.to_bytes((data.bit_length() + 7) // 8, BYTEORDER)
def h(data: str) -> str:
"""Hash un texte"""
if version_info[1] >= 11: # https://docs.python.org/3/library/sys.html#sys.set_int_max_str_digits
set_int_max_str_digits(len(data))
return str(int.from_bytes(sha256(int_to_bytes(int(data))).digest(), BYTEORDER))