Skip to content

Commit

Permalink
🗓 Jan 6, 2024 1:44:03 PM
Browse files Browse the repository at this point in the history
✨ drop_bytes method
🧪 tests added/updated
  • Loading branch information
securisec committed Jan 6, 2024
1 parent c96cf78 commit 7dfcdf8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
bin/
pyvenv.cfg
.envrc
hexfile.bin
share/

.bandit.json
.scannerwork
.DS_Store
Expand Down
26 changes: 25 additions & 1 deletion chepy/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def shuffle(self) -> UtilsT:
unchanged if any other types.
Returns:
Chepy: _description_
Chepy: The Chepy object
"""
data = self.state
if not isinstance(
Expand All @@ -716,3 +716,27 @@ def shuffle(self) -> UtilsT:
random.shuffle(data)
self.state = data
return self

@ChepyDecorators.call_stack
def drop_bytes(self, start: int, length: int) -> UtilsT:
"""Drop bytes from starting index up to length
Args:
start (int): Starting index
length (int): Number of bytes to drop
Raises:
ValueError: If start or length < -1
Returns:
Chepy: The Chepy object
"""
if start < 0 or length < 0:
raise ValueError(
"Start and length must be non-negative integers."
) # pragma: no cover

end = start + length
data = self._convert_to_bytes()
self.state = data[:start] + data[end:]
return self
1 change: 1 addition & 0 deletions chepy/modules/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ class Utils(ChepyCore):
def set(self: UtilsT) -> UtilsT: ...
def regex_to_str(self: UtilsT, all_combo: bool=...) -> UtilsT: ...
def shuffle(self: UtilsT) -> UtilsT: ...
def drop_bytes(self: UtilsT, start: int, length: int) -> UtilsT: ...
4 changes: 4 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,7 @@ def test_shuffle():
assert len(Chepy([1, 2, 3]).shuffle().o) == 3
assert len(Chepy("abc").shuffle().o) == 3
assert len(Chepy(b"abdc").shuffle().o) != 3


def test_drop_bytes():
assert Chepy("hello").drop_bytes(2, 2).o == b"heo"

0 comments on commit 7dfcdf8

Please sign in to comment.