|
@@ -240,12 +240,6 @@ class CryptoEngine(object):
|
|
|
"""
|
|
|
return self._callback
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
def changepassword(self):
|
|
|
"""
|
|
|
Creates a new key. The key itself is actually stored in
|
|
@@ -388,22 +382,24 @@ password again")
|
|
|
"""
|
|
|
prepare data before encrypting
|
|
|
"""
|
|
|
+ return obj
|
|
|
|
|
|
- plaintext = _TAG + obj
|
|
|
- numblocks = (len(plaintext)/blocksize) + 1
|
|
|
- newdatasize = blocksize*numblocks
|
|
|
- return plaintext.ljust(newdatasize)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
def _retrievedata(self, plaintext):
|
|
|
"""
|
|
|
retrieve encrypted data
|
|
|
"""
|
|
|
- if (plaintext.startswith(_TAG)):
|
|
|
- plaintext = plaintext[len(_TAG):]
|
|
|
- else:
|
|
|
- raise CryptoBadKeyException("Error decrypting, bad key")
|
|
|
+ return plaintext
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- try:
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -411,9 +407,9 @@ password again")
|
|
|
|
|
|
|
|
|
|
|
|
- return cPickle.loads(plaintext)
|
|
|
- except (TypeError, ValueError, cPickle.UnpicklingError, EOFError):
|
|
|
- return plaintext
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
class DummyCryptoEngine(CryptoEngine):
|
|
@@ -433,8 +429,8 @@ class DummyCryptoEngine(CryptoEngine):
|
|
|
def changepassword(self):
|
|
|
return ''
|
|
|
|
|
|
-
|
|
|
-class CryptoEngineOld(CryptoEngine):
|
|
|
+
|
|
|
+class CryptoEngineOld(CryptoEngine):
|
|
|
|
|
|
def _getcipher_real(self, key, algo):
|
|
|
"""
|
|
@@ -480,3 +476,34 @@ class CryptoEngineOld(CryptoEngine):
|
|
|
break
|
|
|
newkeylen = i
|
|
|
return key.ljust(newkeylen)
|
|
|
+
|
|
|
+ def _preparedata(self, obj, blocksize):
|
|
|
+ """
|
|
|
+ prepare data before encrypting
|
|
|
+ """
|
|
|
+
|
|
|
+ plaintext = _TAG + obj
|
|
|
+ numblocks = (len(plaintext)/blocksize) + 1
|
|
|
+ newdatasize = blocksize*numblocks
|
|
|
+ return plaintext.ljust(newdatasize)
|
|
|
+
|
|
|
+ def _retrievedata(self, plaintext):
|
|
|
+ """
|
|
|
+ retrieve encrypted data
|
|
|
+ """
|
|
|
+ if (plaintext.startswith(_TAG)):
|
|
|
+ plaintext = plaintext[len(_TAG):]
|
|
|
+ else:
|
|
|
+ raise CryptoBadKeyException("Error decrypting, bad key")
|
|
|
+
|
|
|
+ try:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return cPickle.loads(plaintext)
|
|
|
+ except (TypeError, ValueError, cPickle.UnpicklingError, EOFError):
|
|
|
+ return plaintext
|