Skip to content

Commit 618e0d3

Browse files
committed
style: 💄 typing hints
1 parent 75aae54 commit 618e0d3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pyencrypt/encrypt.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33
from pathlib import Path
4+
from typing import Optional
45

56
import python_minifier
67

@@ -17,7 +18,7 @@
1718

1819
def _encrypt_file(
1920
data: bytes,
20-
key: bytes,
21+
key: str,
2122
) -> bytes:
2223
return aes_encrypt(data, key)
2324

@@ -32,7 +33,7 @@ def can_encrypt(path: Path) -> bool:
3233
return True
3334

3435

35-
def encrypt_key(key: bytes) -> str:
36+
def encrypt_key(key: bytes):
3637
ascii_ls = [ord(x) for x in key.decode()]
3738
numbers = generate_rsa_number(2048)
3839
e, n = numbers['e'], numbers['n']
@@ -48,7 +49,7 @@ def encrypt_key(key: bytes) -> str:
4849
return 'O'.join(map(str, cipher_ls)), numbers['d'], numbers['n']
4950

5051

51-
def generate_so_file(cipher_key: str, d: int, n: int, base_dir: Path = None, license: bool = False) -> Path:
52+
def generate_so_file(cipher_key: str, d: int, n: int, base_dir: Optional[Path] = None, license: bool = False) -> Path:
5253
private_key = f'{n}O{d}'
5354
path = Path(os.path.abspath(__file__)).parent
5455

@@ -80,9 +81,7 @@ def generate_so_file(cipher_key: str, d: int, n: int, base_dir: Path = None, lic
8081
loader_origin_file_path.touch(exist_ok=True)
8182
loader_origin_file_path.write_text(f"{decrypt_source}\n{loader_source}")
8283

83-
loader_file_path.write_text(
84-
python_minifier.minify(loader_origin_file_path.read_text())
85-
)
84+
loader_file_path.write_text(python_minifier.minify(loader_origin_file_path.read_text()))
8685

8786
from setuptools import setup # isort:skip
8887
from Cython.Build import cythonize
@@ -95,7 +94,7 @@ def generate_so_file(cipher_key: str, d: int, n: int, base_dir: Path = None, lic
9594
return list(temp_dir.glob('loader.cpython-*-*.so'))[0].absolute()
9695

9796

98-
def encrypt_file(path: Path, key: str, delete_origin: bool = False, new_path: Path = None):
97+
def encrypt_file(path: Path, key: str, delete_origin: bool = False, new_path: Optional[Path] = None):
9998
if not can_encrypt(path):
10099
raise Exception(f"{path.name} can't be encrypted.")
101100
encrypted_data = _encrypt_file(path.read_bytes(), key)

0 commit comments

Comments
 (0)