Python hashlib.__dict__() Examples
The following are 7
code examples of hashlib.__dict__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hashlib
, or try the search function
.
Example #1
Source File: test_hashlib.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_get_builtin_constructor(self): get_builtin_constructor = hashlib.__dict__[ '__get_builtin_constructor'] self.assertRaises(ValueError, get_builtin_constructor, 'test') try: import _md5 except ImportError: pass # This forces an ImportError for "import _md5" statements sys.modules['_md5'] = None try: self.assertRaises(ValueError, get_builtin_constructor, 'md5') finally: if '_md5' in locals(): sys.modules['_md5'] = _md5 else: del sys.modules['_md5'] self.assertRaises(TypeError, get_builtin_constructor, 3)
Example #2
Source File: test_hashlib.py From BinderFilter with MIT License | 6 votes |
def test_get_builtin_constructor(self): get_builtin_constructor = hashlib.__dict__[ '__get_builtin_constructor'] self.assertRaises(ValueError, get_builtin_constructor, 'test') try: import _md5 except ImportError: pass # This forces an ImportError for "import _md5" statements sys.modules['_md5'] = None try: self.assertRaises(ValueError, get_builtin_constructor, 'md5') finally: if '_md5' in locals(): sys.modules['_md5'] = _md5 else: del sys.modules['_md5'] self.assertRaises(TypeError, get_builtin_constructor, 3)
Example #3
Source File: test_hashlib.py From oss-ftp with MIT License | 6 votes |
def test_get_builtin_constructor(self): get_builtin_constructor = hashlib.__dict__[ '__get_builtin_constructor'] self.assertRaises(ValueError, get_builtin_constructor, 'test') try: import _md5 except ImportError: pass # This forces an ImportError for "import _md5" statements sys.modules['_md5'] = None try: self.assertRaises(ValueError, get_builtin_constructor, 'md5') finally: if '_md5' in locals(): sys.modules['_md5'] = _md5 else: del sys.modules['_md5'] self.assertRaises(TypeError, get_builtin_constructor, 3)
Example #4
Source File: test_hashlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_get_builtin_constructor(self): get_builtin_constructor = hashlib.__dict__[ '__get_builtin_constructor'] self.assertRaises(ValueError, get_builtin_constructor, 'test') try: import _md5 except ImportError: pass # This forces an ImportError for "import _md5" statements sys.modules['_md5'] = None try: self.assertRaises(ValueError, get_builtin_constructor, 'md5') finally: if '_md5' in locals(): sys.modules['_md5'] = _md5 else: del sys.modules['_md5'] self.assertRaises(TypeError, get_builtin_constructor, 3)
Example #5
Source File: test_hashlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_get_builtin_constructor(self): get_builtin_constructor = hashlib.__dict__[ '__get_builtin_constructor'] self.assertRaises(ValueError, get_builtin_constructor, 'test') try: import _md5 except ImportError: pass # This forces an ImportError for "import _md5" statements sys.modules['_md5'] = None try: self.assertRaises(ValueError, get_builtin_constructor, 'md5') finally: if '_md5' in locals(): sys.modules['_md5'] = _md5 else: del sys.modules['_md5'] self.assertRaises(TypeError, get_builtin_constructor, 3)
Example #6
Source File: test_hashlib.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_get_builtin_constructor(self): get_builtin_constructor = hashlib.__dict__[ '__get_builtin_constructor'] self.assertRaises(ValueError, get_builtin_constructor, 'test') try: import _md5 except ImportError: pass # This forces an ImportError for "import _md5" statements sys.modules['_md5'] = None try: self.assertRaises(ValueError, get_builtin_constructor, 'md5') finally: if '_md5' in locals(): sys.modules['_md5'] = _md5 else: del sys.modules['_md5'] self.assertRaises(TypeError, get_builtin_constructor, 3)
Example #7
Source File: record.py From Commander with MIT License | 5 votes |
def get_totp_code(url): # type: (str) -> (str, int) or None comp = parse.urlparse(url) if comp.scheme == 'otpauth': secret = None algorithm = 'SHA1' digits = 6 period = 30 for k, v in parse.parse_qsl(comp.query): if k == 'secret': secret = v elif k == 'algorithm': algorithm = v elif k == 'digits': digits = int(v) elif k == 'period': period = int(v) if secret: tm_base = int(datetime.datetime.now().timestamp()) tm = tm_base / period alg = algorithm.lower() if alg in hashlib.__dict__: reminder = len(secret) % 8 if reminder in {2, 4, 5, 7}: padding = '=' * (8 - reminder) secret += padding key = base64.b32decode(secret, casefold=True) msg = int(tm).to_bytes(8, byteorder='big') hash = hashlib.__dict__[alg] hm = hmac.new(key, msg=msg, digestmod=hash) digest = hm.digest() offset = digest[-1] & 0x0f base = bytearray(digest[offset:offset + 4]) base[0] = base[0] & 0x7f code_int = int.from_bytes(base, byteorder='big') code = str(code_int % (10 ** digits)) if len(code) < digits: code = code.rjust(digits, '0') return code, period - (tm_base % period), period else: raise Error('Unsupported hash algorithm: {0}'.format(algorithm))