mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 04:12:23 +01:00
41e86f6519
Co-authored-by: Marius Andra <marius.andra@gmail.com>
26 lines
674 B
Python
26 lines
674 B
Python
import hashlib
|
|
import hmac
|
|
|
|
|
|
def md5Hex(data: str | None) -> str | None:
|
|
if data is None:
|
|
return None
|
|
return hashlib.md5(data.encode()).hexdigest()
|
|
|
|
|
|
def sha256Hex(data: str | None) -> str | None:
|
|
if data is None:
|
|
return None
|
|
return hashlib.sha256(data.encode()).hexdigest()
|
|
|
|
|
|
def sha256HmacChainHex(data: list) -> str:
|
|
if len(data) < 2:
|
|
raise ValueError("Data array must contain at least two elements.")
|
|
|
|
hmac_obj = hmac.new(data[0].encode(), data[1].encode(), hashlib.sha256)
|
|
for i in range(2, len(data)):
|
|
hmac_obj = hmac.new(hmac_obj.digest(), data[i].encode(), hashlib.sha256)
|
|
|
|
return hmac_obj.hexdigest()
|