Skip to content

Commit

Permalink
Merge pull request #87 from vil02/assert_in_split_data_and_signature
Browse files Browse the repository at this point in the history
style: remove `assert` from `split_data_and_signature`
  • Loading branch information
vil02 committed Sep 2, 2024
2 parents 3e397b7 + 75d5edc commit d49f5d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion puzzle_generator/encryption_algorithms/simple/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def merge_data_and_signature(in_data: bytes, in_signature: bytes) -> bytes:
def split_data_and_signature(
in_bytes: bytes, signature_size: int
) -> typing.Tuple[bytes, bytes]:
assert len(in_bytes) >= signature_size # nosec B101
if len(in_bytes) < signature_size:
raise ValueError("in_bytes is shorter than signature_size")
data = in_bytes[:-signature_size]
signature = in_bytes[-signature_size:]
return data, signature
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.0"
version = "0.12.1"
description = "Generates python code representing a puzzle"
authors = ["piotr.idzik <vil02_puzzle_generator@10g.pl>"]
readme = "./puzzle_generator/README.md"
Expand Down
5 changes: 5 additions & 0 deletions tests/encryption_algorithms/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
def test_digest_size(in_signature_params: dict[str, str]) -> None:
some_hash = eac.sign_bytes(b"some_msg", b"some_key", in_signature_params)
assert eac.digest_size(in_signature_params) == len(some_hash)


def test_split_data_and_signature_raises():
with pytest.raises(ValueError, match="in_bytes is shorter than signature_size"):
eac.split_data_and_signature(b"0", 2)

0 comments on commit d49f5d9

Please sign in to comment.