eric6/Utilities/crypto/py3AES.py

changeset 7628
f904d0eef264
parent 7360
9190402e4505
child 7781
607a6098cb44
diff -r 7f643d41464e -r f904d0eef264 eric6/Utilities/crypto/py3AES.py
--- a/eric6/Utilities/crypto/py3AES.py	Wed Jun 17 17:12:21 2020 +0200
+++ b/eric6/Utilities/crypto/py3AES.py	Wed Jun 17 20:18:54 2020 +0200
@@ -240,8 +240,8 @@
                 size == self.KeySize["SIZE_256"] and
                 ((currentSize % size) == 16)
             ):
-                for l in range(4):
-                    t[l] = self.__getSBoxValue(t[l])
+                for ll in range(4):
+                    t[ll] = self.__getSBoxValue(t[ll])
 
             # We XOR t with the four-byte block 16, 24, 32 bytes before the new
             # expanded key. This becomes the next four bytes in the expanded
@@ -547,10 +547,10 @@
         block = self.__aes_main(block, expandedKey, nbrRounds)
 
         # unmap the block again into the output
-        for k in range(4):
+        for kk in range(4):
             # iterate over the rows
-            for l in range(4):
-                output[k * 4 + l] = block[k + l * 4]
+            for ll in range(4):
+                output[kk * 4 + ll] = block[kk + ll * 4]
         return bytes(output)
 
     # decrypts a 128 bit input block against the given key of size specified
@@ -600,10 +600,10 @@
         # decrypt the block using the expandedKey
         block = self.__aes_invMain(block, expandedKey, nbrRounds)
         # unmap the block again into the output
-        for k in range(4):
+        for kk in range(4):
             # iterate over the rows
-            for l in range(4):
-                output[k * 4 + l] = block[k + l * 4]
+            for ll in range(4):
+                output[kk * 4 + ll] = block[kk + ll * 4]
         return output
 
 
@@ -833,13 +833,14 @@
     @param data data to be encrypted (bytes)
     @param mode mode of operations (0, 1 or 2)
     @return encrypted data prepended with the initialization vector (bytes)
+    @exception ValueError raised to indicate an invalid key size
     """
     key = bytearray(key)
     if mode == AESModeOfOperation.ModeOfOperation["CBC"]:
         data = append_PKCS7_padding(data)
     keysize = len(key)
-    assert keysize in AES.KeySize.values(), \
-        'invalid key size: {0}'.format(keysize)
+    if keysize not in AES.KeySize.values():
+        raise ValueError('invalid key size: {0}'.format(keysize))
     # create a new iv using random data
     iv = bytearray([i for i in os.urandom(16)])
     moo = AESModeOfOperation()
@@ -859,11 +860,12 @@
         (bytes)
     @param mode mode of operations (0, 1 or 2)
     @return decrypted data (bytes)
+    @exception ValueError raised to indicate an invalid key size
     """
     key = bytearray(key)
     keysize = len(key)
-    assert keysize in AES.KeySize.values(), \
-        'invalid key size: {0}'.format(keysize)
+    if keysize not in AES.KeySize.values():
+        raise ValueError('invalid key size: {0}'.format(keysize))
     # iv is first 16 bytes
     iv = bytearray(data[:16])
     data = bytearray(data[16:])

eric ide

mercurial