test_cipher.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:sagecipher 作者: p-sherratt 项目源码 文件源码
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())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号