def test_passlib(self):
# force import of passlib pbkdf2 function, and compare headers/keys
# generated from both hashlib and passlib
self.cipher1 = sagecipher.Cipher()
try:
import builtins
except ImportError:
import __builtin__ as builtins
realimport = builtins.__import__
def myimport(*args, **kwargs):
if args[0] == 'hashlib' and args[3] is not None and 'pbkdf2_hmac' in args[3]:
raise ImportError
return realimport(*args, **kwargs)
builtins.__import__ = myimport
del(sagecipher.cipher.pbkdf2_hashlib)
reload(sagecipher.cipher)
reload(sagecipher)
self.assertIn('pbkdf2_passlib', dir(sagecipher.cipher))
self.assertNotIn('pbkdf2_hashlib', dir(sagecipher.cipher))
self.cipher2 = sagecipher.Cipher(self.cipher1.header())
self.assertEqual(self.cipher1.header(), self.cipher2.header())
评论列表
文章目录