Skip to content

Commit d44aca1

Browse files
committed
fix: update ruff config and fix linting issues
- Move deprecated top-level ruff settings to lint section - Fix import sorting and formatting issues - Update type annotations to use modern syntax (list/tuple instead of List/Tuple) - Add explicit strict parameter to zip() calls - Remove trailing whitespace
1 parent 306ae42 commit d44aca1

5 files changed

Lines changed: 18 additions & 19 deletions

File tree

git_safe/crypto.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Cryptographic operations for git-safe
33
"""
44

5+
import hashlib
6+
import hmac
57
import os
68
import struct
7-
import hmac
8-
import hashlib
99

10-
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
1110
from cryptography.hazmat.backends import default_backend
11+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
1212

1313
from .constants import BLOCK_SIZE, CTR_NONCE_LEN, HMAC_CHECK_LEN
1414

@@ -28,7 +28,7 @@ def ctr_decrypt(aes_key: bytes, nonce: bytes, data: bytes) -> bytes:
2828
# Create cipher in ECB mode for manual CTR implementation
2929
cipher = Cipher(algorithms.AES(aes_key), modes.ECB(), backend=default_backend()) # nosec B305
3030
encryptor = cipher.encryptor()
31-
31+
3232
out = bytearray()
3333

3434
for off in range(0, len(data), BLOCK_SIZE):
@@ -45,7 +45,7 @@ def ctr_decrypt(aes_key: bytes, nonce: bytes, data: bytes) -> bytes:
4545
ctr = counter_bytes[:BLOCK_SIZE]
4646

4747
stream = encryptor.update(ctr)
48-
out.extend(b ^ s for b, s in zip(block, stream))
48+
out.extend(b ^ s for b, s in zip(block, stream, strict=False))
4949

5050
# Finalize the encryptor (required by cryptography library)
5151
encryptor.finalize()

git_safe/file_ops.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
from pathlib import Path
6-
from typing import List, Optional
76

87
from .constants import CTR_NONCE_LEN, HMAC_CHECK_LEN, MAGIC
98
from .crypto import compute_hmac, ctr_decrypt, ctr_encrypt, generate_nonce, verify_hmac
@@ -61,7 +60,7 @@ def encrypt_file(file_path: Path, aes_key: bytes, hmac_key: bytes, backup: bool
6160

6261

6362
def decrypt_file(
64-
file_path: Path, aes_key: bytes, hmac_key: bytes, output_path: Optional[Path] = None, verify_only: bool = False
63+
file_path: Path, aes_key: bytes, hmac_key: bytes, output_path: Path | None = None, verify_only: bool = False
6564
) -> bool:
6665
"""
6766
Decrypt a file, always overwriting the original file in-place.
@@ -147,7 +146,7 @@ def is_encrypted_file(file_path: Path) -> bool:
147146
return False
148147

149148

150-
def find_encrypted_files(root_path: Path) -> List[Path]:
149+
def find_encrypted_files(root_path: Path) -> list[Path]:
151150
"""
152151
Find all encrypted files in a directory tree.
153152

git_safe/keyfile.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import struct
77
from pathlib import Path
8-
from typing import Optional, Tuple
98

109
import gnupg
1110

@@ -18,7 +17,7 @@ class KeyfileError(Exception):
1817
pass
1918

2019

21-
def generate_keys() -> Tuple[bytes, bytes]:
20+
def generate_keys() -> tuple[bytes, bytes]:
2221
"""
2322
Generate new AES and HMAC keys.
2423
@@ -54,7 +53,7 @@ def create_keyfile_data(aes_key: bytes, hmac_key: bytes) -> bytes:
5453
return bytes(data)
5554

5655

57-
def load_keyfile(path: Path) -> Tuple[bytes, bytes]:
56+
def load_keyfile(path: Path) -> tuple[bytes, bytes]:
5857
"""
5958
Load keys from a keyfile.
6059
@@ -130,7 +129,7 @@ def save_keyfile(path: Path, aes_key: bytes, hmac_key: bytes) -> None:
130129
raise KeyfileError(f"Cannot save keyfile {path}: {e}") from e
131130

132131

133-
def export_key_gpg(keyfile_path: Path, gpg_recipient: str, output_path: Optional[Path] = None) -> Path:
132+
def export_key_gpg(keyfile_path: Path, gpg_recipient: str, output_path: Path | None = None) -> Path:
134133
"""
135134
Export keyfile encrypted with GPG.
136135
@@ -170,7 +169,7 @@ def export_key_gpg(keyfile_path: Path, gpg_recipient: str, output_path: Optional
170169
raise KeyfileError(f"Failed to export GPG keyfile: {e}") from e
171170

172171

173-
def import_key_gpg(encrypted_keyfile_path: Path, output_path: Optional[Path] = None) -> Path:
172+
def import_key_gpg(encrypted_keyfile_path: Path, output_path: Path | None = None) -> Path:
174173
"""
175174
Import keyfile decrypted from GPG.
176175
@@ -216,7 +215,7 @@ def import_key_gpg(encrypted_keyfile_path: Path, output_path: Optional[Path] = N
216215
raise KeyfileError(f"Failed to import GPG keyfile: {e}") from e
217216

218217

219-
def generate_keyfile(path: Path) -> Tuple[bytes, bytes]:
218+
def generate_keyfile(path: Path) -> tuple[bytes, bytes]:
220219
"""
221220
Generate a new keyfile with random keys.
222221

git_safe/patterns.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
from pathlib import Path
6-
from typing import List, Optional
76

87
from pathspec import PathSpec, patterns
98

@@ -14,7 +13,7 @@ class PatternError(Exception):
1413
pass
1514

1615

17-
def parse_gitattributes(gitattributes_path: Optional[Path] = None) -> PathSpec:
16+
def parse_gitattributes(gitattributes_path: Path | None = None) -> PathSpec:
1817
"""
1918
Parse .gitattributes file and extract patterns for git-safe filter.
2019
@@ -63,7 +62,7 @@ def parse_gitattributes(gitattributes_path: Optional[Path] = None) -> PathSpec:
6362
return PathSpec.from_lines(patterns.GitWildMatchPattern, patterns_list)
6463

6564

66-
def find_matching_files(root_path: Path, pathspec: PathSpec) -> List[Path]:
65+
def find_matching_files(root_path: Path, pathspec: PathSpec) -> list[Path]:
6766
"""
6867
Find all files matching the pathspec patterns.
6968
@@ -85,7 +84,7 @@ def find_matching_files(root_path: Path, pathspec: PathSpec) -> List[Path]:
8584
return matching_files
8685

8786

88-
def should_encrypt_file(file_path: Path, root_path: Optional[Path] = None) -> bool:
87+
def should_encrypt_file(file_path: Path, root_path: Path | None = None) -> bool:
8988
"""
9089
Check if a file should be encrypted based on .gitattributes patterns.
9190

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ ensure_newline_before_comments = true
9393
[tool.ruff]
9494
target-version = "py311"
9595
line-length = 120
96+
97+
[tool.ruff.lint]
9698
select = [
9799
"E", # pycodestyle errors
98100
"W", # pycodestyle warnings
@@ -108,7 +110,7 @@ ignore = [
108110
"C901", # too complex
109111
]
110112

111-
[tool.ruff.per-file-ignores]
113+
[tool.ruff.lint.per-file-ignores]
112114
"__init__.py" = ["F401"]
113115

114116
[tool.mypy]

0 commit comments

Comments
 (0)