From a652e0267700bfbd41c2ff022f0f115e775373d3 Mon Sep 17 00:00:00 2001 From: clach04 Date: Mon, 1 May 2017 21:33:59 -0700 Subject: [PATCH] Support older Python 2.7 versions Python 2.7.2 and 2.7.3 struct.unpack() fail with: error: unpack requires a string argument of length 4 Due to bytearray parameter. Casting as bytes() works for both Python 2.7.x and 3.x. http://stackoverflow.com/questions/20612587/struct-unpack-with-bytearrays has more information --- pyaes/aes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyaes/aes.py b/pyaes/aes.py index c6e8bc0..407a861 100644 --- a/pyaes/aes.py +++ b/pyaes/aes.py @@ -145,7 +145,7 @@ def __init__(self, key): KC = len(key) // 4 # Convert the key into ints - tk = [ struct.unpack('>i', key[i:i + 4])[0] for i in xrange(0, len(key), 4) ] + tk = [ struct.unpack('>i', bytes(key[i:i + 4]))[0] for i in xrange(0, len(key), 4) ] # Copy values into round key arrays for i in xrange(0, KC):