Skip to content

Commit

Permalink
HardenedRC4 和 ARC4 的 keystream() 方法现在不再允许小于 0 的 offset 和 length 参数
Browse files Browse the repository at this point in the history
  • Loading branch information
nukemiko committed Oct 24, 2022
1 parent 845b273 commit 39a7022
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/libtakiyasha/qmc/qmcdataciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def keystream(self, offset: IntegerLike, length: IntegerLike, /) -> Generator[in
pending = toint_nofloat(length)
done = 0
offset = toint_nofloat(offset)
if offset < 0:
raise ValueError("first argument 'offset' must be a non-negative integer")
if pending < 0:
raise ValueError("second argument 'length' must be a non-negative integer")

def mark(p: int) -> None:
nonlocal pending, done, offset
Expand Down
6 changes: 4 additions & 2 deletions src/libtakiyasha/stdciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,11 @@ def __init__(self, key: BytesLike, /) -> None:

def keystream(self, offset: IntegerLike, length: IntegerLike, /) -> Generator[int, None, None]:
offset = toint_nofloat(offset)
if offset < 0:
raise ValueError(f"offset must be poritive integer or 0, not {offset}")
length = toint_nofloat(length)
if offset < 0:
raise ValueError("first argument 'offset' must be a non-negative integer")
if length < 0:
raise ValueError("second argument 'length' must be a non-negative integer")

for i in range(offset, offset + length):
yield self._meta_keystream[i % 256]

0 comments on commit 39a7022

Please sign in to comment.