Skip to content

Commit

Permalink
Merge pull request #93 from vil02/asserts_in_spiced
Browse files Browse the repository at this point in the history
style: remove `assert`s from `spiced`
  • Loading branch information
vil02 committed Sep 5, 2024
2 parents ec982be + ca1555b commit f680c79
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions puzzle_generator/configurators/simple/spiced.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_encrypt(self):

def get_needed_objects(self):
return csc.OBJECTS + [
sse.must_be_nonempty,
sse.get_decrypt,
]

Expand Down
13 changes: 9 additions & 4 deletions puzzle_generator/encryption_algorithms/simple/spiced.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
)


def must_be_nonempty(in_list: typing.List[bytes]) -> None:
if not in_list:
raise ValueError("in_list must be nonempty")


def get_encrypt(
proc_spices: typing.List[bytes],
signature_spices: typing.List[bytes],
scrypt_params,
signature_params,
) -> typing.Callable[[bytes, bytes], bytes]:
assert proc_spices # nosec B101
assert signature_spices # nosec B101
must_be_nonempty(proc_spices)
must_be_nonempty(signature_spices)

def _encrypt(in_bytes: bytes, in_pass: bytes) -> bytes:
signature_spice = secrets.choice(signature_spices)
Expand All @@ -39,8 +44,8 @@ def get_decrypt(
scrypt_params,
signature_params,
) -> typing.Callable[[bytes, bytes], bytes | None]:
assert proc_spices # nosec B101
assert signature_spices # nosec B101
must_be_nonempty(proc_spices)
must_be_nonempty(signature_spices)

def _decrypt(in_bytes: bytes, in_pass: bytes) -> bytes | None:
for proc_spice in proc_spices:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "puzzle-generator"
version = "0.12.2"
version = "0.12.3"
description = "Generates python code representing a puzzle"
authors = ["piotr.idzik <vil02_puzzle_generator@10g.pl>"]
readme = "./puzzle_generator/README.md"
Expand Down
8 changes: 8 additions & 0 deletions tests/encryption_algorithms/test_spiced.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

import puzzle_generator.encryption_algorithms.simple.spiced as ess


def test_must_be_nonempty_raises() -> None:
with pytest.raises(ValueError, match="in_list must be nonempty"):
ess.must_be_nonempty([])

0 comments on commit f680c79

Please sign in to comment.