[+] improve crypto
This commit is contained in:
parent
731c507b95
commit
add9d858d8
@ -1,7 +1,7 @@
|
|||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from typing import (Literal, overload,)
|
from typing import (Literal, overload, Optional,)
|
||||||
|
|
||||||
class PasswordUtils:
|
class PasswordUtils:
|
||||||
@overload
|
@overload
|
||||||
@ -25,10 +25,12 @@ class PasswordUtils:
|
|||||||
cls,
|
cls,
|
||||||
secret: str,
|
secret: str,
|
||||||
mode: Literal['bytes', 'base64'],
|
mode: Literal['bytes', 'base64'],
|
||||||
|
salt: Optional[bytes] = None,
|
||||||
) -> tuple[str, str] | tuple[bytes, bytes]:
|
) -> tuple[str, str] | tuple[bytes, bytes]:
|
||||||
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt
|
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt
|
||||||
|
|
||||||
salt = os.urandom(16)
|
if salt is None:
|
||||||
|
salt = os.urandom(16)
|
||||||
|
|
||||||
# derive
|
# derive
|
||||||
kdf = Scrypt(
|
kdf = Scrypt(
|
||||||
|
@ -3,7 +3,7 @@ import unittest
|
|||||||
|
|
||||||
|
|
||||||
class TestCrypto(unittest.TestCase):
|
class TestCrypto(unittest.TestCase):
|
||||||
def test_password_utils(self):
|
def test_password_utils(self) -> None:
|
||||||
salt = b'asdfasdfasdf'
|
salt = b'asdfasdfasdf'
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
Loading…
Reference in New Issue
Block a user