mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-15 13:54:43 -06:00
It seems that the codebase is not formatted with the latest ruff version. This PR reformats the codebase with ruff 0.5.7.
28 lines
652 B
Python
28 lines
652 B
Python
"""Util add-on functions."""
|
|
|
|
import hashlib
|
|
import re
|
|
|
|
RE_DIGITS = re.compile(r"\d+")
|
|
|
|
|
|
def password_to_key(password: str) -> bytes:
|
|
"""Generate a AES Key from password."""
|
|
key: bytes = password.encode()
|
|
for _ in range(100):
|
|
key = hashlib.sha256(key).digest()
|
|
return key[:16]
|
|
|
|
|
|
def key_to_iv(key: bytes) -> bytes:
|
|
"""Generate an iv from Key."""
|
|
for _ in range(100):
|
|
key = hashlib.sha256(key).digest()
|
|
return key[:16]
|
|
|
|
|
|
def create_slug(name: str, date_str: str) -> str:
|
|
"""Generate a hash from repository."""
|
|
key = f"{date_str} - {name}".lower().encode()
|
|
return hashlib.sha1(key).hexdigest()[:8]
|