diff --git a/src/libtakiyasha/qmc/qmcdataciphers.py b/src/libtakiyasha/qmc/qmcdataciphers.py index 9544558..47315b0 100644 --- a/src/libtakiyasha/qmc/qmcdataciphers.py +++ b/src/libtakiyasha/qmc/qmcdataciphers.py @@ -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 diff --git a/src/libtakiyasha/stdciphers.py b/src/libtakiyasha/stdciphers.py index 6429386..5bd37d3 100644 --- a/src/libtakiyasha/stdciphers.py +++ b/src/libtakiyasha/stdciphers.py @@ -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]