fix: fallback to getpass.getuser() when os.getlogin() raises OSError
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
"""Keychain: save key to a file, then keys.set("name", file="path"); keys.name.use() to retrieve (use but no print)."""
|
"""Keychain: save key to a file, then keys.set("name", file="path"); keys.name.use() to retrieve (use but no print)."""
|
||||||
import json, os, hashlib, pathlib
|
import json, os, hashlib, pathlib, getpass
|
||||||
|
|
||||||
_PATH = pathlib.Path.home() / "ga_keychain.enc"
|
_PATH = pathlib.Path.home() / "ga_keychain.enc"
|
||||||
_MASK = hashlib.sha256(f"{os.getlogin()}@ga_keychain".encode()).digest()
|
try: _user = os.getlogin()
|
||||||
|
except OSError: _user = getpass.getuser()
|
||||||
|
_MASK = hashlib.sha256(f"{_user}@ga_keychain".encode()).digest()
|
||||||
|
|
||||||
def _xor(data: bytes) -> bytes:
|
def _xor(data: bytes) -> bytes:
|
||||||
return bytes(b ^ _MASK[i % len(_MASK)] for i, b in enumerate(data))
|
return bytes(b ^ _MASK[i % len(_MASK)] for i, b in enumerate(data))
|
||||||
|
|||||||
Reference in New Issue
Block a user