summaryrefslogtreecommitdiffstats
path: root/DeDRM_plugin/aescbc.py
diff options
context:
space:
mode:
authorApprentice Harper <[email protected]>2020-09-26 21:22:47 +0100
committerApprentice Harper <[email protected]>2020-09-26 21:22:47 +0100
commitafa4ac571664368dc27512768a67656ea7dd645a (patch)
tree57ca18d568ce426ce3bfa27b45dff60efa803604 /DeDRM_plugin/aescbc.py
parent4868a7460e39910ad22d0949d26b3250656dea46 (diff)
Starting on Version 7.0 using the work done by others. Completely untested. I will be testing things, but I thought I'd get this base version up for others to give pull requests.
THIS IS ON THE MASTER BRANCH. The Master branch will be Python 3.0 from now on. While Python 2.7 support will not be deliberately broken, all efforts should now focus on Python 3.0 compatibility. I can see a lot of work has been done. There's more to do. I've bumped the version number of everything I came across to the next major number for Python 3.0 compatibility indication. Thanks everyone. I hope to update here at least once a week until we have a stable 7.0 release for calibre 5.0
Diffstat (limited to 'DeDRM_plugin/aescbc.py')
-rw-r--r--DeDRM_plugin/aescbc.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/DeDRM_plugin/aescbc.py b/DeDRM_plugin/aescbc.py
index 5667511..28e1843 100644
--- a/DeDRM_plugin/aescbc.py
+++ b/DeDRM_plugin/aescbc.py
@@ -13,6 +13,8 @@
CryptoPy Artisitic License Version 1.0
See the wonderful pure python package cryptopy-1.2.5
and read its LICENSE.txt for complete license details.
+
+ Adjusted for Python 3 compatibility, September 2020
"""
class CryptoError(Exception):
@@ -101,7 +103,7 @@ class BlockCipher:
numBlocks, numExtraBytes = divmod(len(self.bytesToDecrypt), self.blockSize)
if more == None: # no more calls to decrypt, should have all the data
if numExtraBytes != 0:
- raise DecryptNotBlockAlignedError, 'Data not block aligned on decrypt'
+ raise DecryptNotBlockAlignedError('Data not block aligned on decrypt')
# hold back some bytes in case last decrypt has zero len
if (more != None) and (numExtraBytes == 0) and (numBlocks >0) :
@@ -143,7 +145,7 @@ class padWithPadLen(Pad):
def removePad(self, paddedBinaryString, blockSize):
""" Remove padding from a binary string """
if not(0<len(paddedBinaryString)):
- raise DecryptNotBlockAlignedError, 'Expected More Data'
+ raise DecryptNotBlockAlignedError('Expected More Data')
return paddedBinaryString[:-ord(paddedBinaryString[-1])]
class noPadding(Pad):
@@ -451,7 +453,7 @@ class AES(Rijndael):
def __init__(self, key = None, padding = padWithPadLen(), keySize=16):
""" Initialize AES, keySize is in bytes """
if not (keySize == 16 or keySize == 24 or keySize == 32) :
- raise BadKeySizeError, 'Illegal AES key size, must be 16, 24, or 32 bytes'
+ raise BadKeySizeError('Illegal AES key size, must be 16, 24, or 32 bytes')
Rijndael.__init__( self, key, padding=padding, keySize=keySize, blockSize=16 )