Skip to content

Commit d4830b8

Browse files
committed
process rotate checks groupsize using dict lookup
1 parent f6b3795 commit d4830b8

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

kaitaistruct.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,14 @@ def process_xor_many(data, key):
348348
else:
349349
return bytes(a ^ b for a, b in zip(data, itertools.cycle(key)))
350350

351-
precomputed_rotations = {amount:[(i << amount) & 0xff | (i >> (-amount & 7)) for i in range(256)] for amount in range(9)}
351+
precomputed_rotations = {(amount,1):[(i << amount) & 0xff | (i >> (-amount & 7)) for i in range(256)] for amount in range(9)}
352352

353353
@staticmethod
354354
def process_rotate_left(data, amount, group_size):
355-
if group_size != 1:
356-
raise Exception(
357-
"unable to rotate group of %d bytes yet" %
358-
(group_size,)
359-
)
360-
361355
if amount == 0:
362356
return data
363357

364-
translate = KaitaiStream.precomputed_rotations[amount]
358+
translate = KaitaiStream.precomputed_rotations[amount,group_size]
365359
if PY2:
366360
return bytes(bytearray(translate[a] for a in bytearray(data)))
367361
else:

0 commit comments

Comments
 (0)