From add9d858d8bf8f79b55f54d974886f82db00f1e5 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Mon, 3 Mar 2025 18:00:51 +0300 Subject: [PATCH] [+] improve crypto --- python/online/fxreader/pr34/commands_typed/crypto.py | 6 ++++-- python/online/fxreader/pr34/tests/test_crypto.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/python/online/fxreader/pr34/commands_typed/crypto.py b/python/online/fxreader/pr34/commands_typed/crypto.py index fb20856..ab3a8b6 100644 --- a/python/online/fxreader/pr34/commands_typed/crypto.py +++ b/python/online/fxreader/pr34/commands_typed/crypto.py @@ -1,7 +1,7 @@ import base64 import os -from typing import (Literal, overload,) +from typing import (Literal, overload, Optional,) class PasswordUtils: @overload @@ -25,10 +25,12 @@ class PasswordUtils: cls, secret: str, mode: Literal['bytes', 'base64'], + salt: Optional[bytes] = None, ) -> tuple[str, str] | tuple[bytes, bytes]: from cryptography.hazmat.primitives.kdf.scrypt import Scrypt - salt = os.urandom(16) + if salt is None: + salt = os.urandom(16) # derive kdf = Scrypt( diff --git a/python/online/fxreader/pr34/tests/test_crypto.py b/python/online/fxreader/pr34/tests/test_crypto.py index f4da055..60e7881 100644 --- a/python/online/fxreader/pr34/tests/test_crypto.py +++ b/python/online/fxreader/pr34/tests/test_crypto.py @@ -3,7 +3,7 @@ import unittest class TestCrypto(unittest.TestCase): - def test_password_utils(self): + def test_password_utils(self) -> None: salt = b'asdfasdfasdf' self.assertEqual(