本文整理汇总了Python中_md5.new方法的典型用法代码示例。如果您正苦于以下问题:Python _md5.new方法的具体用法?Python _md5.new怎么用?Python _md5.new使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_md5
的用法示例。
在下文中一共展示了_md5.new方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_large_update
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def test_large_update(self):
aas = 'a' * 128
bees = 'b' * 127
cees = 'c' * 126
abcs = aas + bees + cees
for name in self.supported_hash_names:
m1 = hashlib.new(name)
m1.update(aas)
m1.update(bees)
m1.update(cees)
m2 = hashlib.new(name)
m2.update(abcs)
self.assertEqual(m1.digest(), m2.digest(), name+' update problem.')
m3 = hashlib.new(name, abcs)
self.assertEqual(m1.digest(), m3.digest(), name+' new problem.')
示例2: __get_builtin_constructor
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def __get_builtin_constructor(name):
if name in ('SHA1', 'sha1'):
import _sha
return _sha.new
elif name in ('MD5', 'md5'):
import _md5
return _md5.new
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
import _sha256
bs = name[3:]
if bs == '256':
return _sha256.sha256
elif bs == '224':
return _sha256.sha224
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
import _sha512
bs = name[3:]
if bs == '512':
return _sha512.sha512
elif bs == '384':
return _sha512.sha384
raise ValueError('unsupported hash type %s' % name)
示例3: __get_builtin_constructor
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def __get_builtin_constructor(name):
if name in ('SHA1', 'sha1'):
import _sha
return _sha.new
elif name in ('MD5', 'md5'):
import _md5
return _md5.new
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
import _sha256
bs = name[3:]
if bs == '256':
return _sha256.sha256
elif bs == '224':
return _sha256.sha224
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
import _sha512
bs = name[3:]
if bs == '512':
return _sha512.sha512
elif bs == '384':
return _sha512.sha384
raise ValueError, "unsupported hash type"
示例4: __get_builtin_constructor
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def __get_builtin_constructor(name):
try:
if name in ('SHA1', 'sha1'):
import _sha
return _sha.new
elif name in ('MD5', 'md5'):
import _md5
return _md5.new
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
import _sha256
bs = name[3:]
if bs == '256':
return _sha256.sha256
elif bs == '224':
return _sha256.sha224
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
import _sha512
bs = name[3:]
if bs == '512':
return _sha512.sha512
elif bs == '384':
return _sha512.sha384
except ImportError:
pass # no extension module, this hash is unsupported.
raise ValueError('unsupported hash type %s' % name)
示例5: __py_new
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def __py_new(name, string=''):
"""new(name, string='') - Return a new hashing object using the named algorithm;
optionally initialized with a string.
"""
return __get_builtin_constructor(name)(string)
示例6: __hash_new
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def __hash_new(name, string=''):
"""new(name, string='') - Return a new hashing object using the named algorithm;
optionally initialized with a string.
"""
try:
return _hashlib.new(name, string)
except ValueError:
# If the _hashlib module (OpenSSL) doesn't support the named
# hash, try using our builtin implementations.
# This allows for SHA224/256 and SHA384/512 support even though
# the OpenSSL library prior to 0.9.8 doesn't provide them.
return __get_builtin_constructor(name)(string)
示例7: __get_builtin_constructor
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def __get_builtin_constructor(name):
try:
if name in ('SHA1', 'sha1'):
import _sha
return _sha.new
elif name in ('MD5', 'md5'):
import _md5
return _md5.new
elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
import _sha256
bs = name[3:]
if bs == '256':
return _sha256.sha256
elif bs == '224':
return _sha256.sha224
elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
import _sha512
bs = name[3:]
if bs == '512':
return _sha512.sha512
elif bs == '384':
return _sha512.sha384
except ImportError:
pass # no extension module, this hash is unsupported.
raise ValueError('unsupported hash type ' + name)
示例8: test_hexdigest
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def test_hexdigest(self):
for name in self.supported_hash_names:
h = hashlib.new(name)
self.assertTrue(hexstr(h.digest()) == h.hexdigest())
示例9: check
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def check(self, name, data, digest):
constructors = self.constructors_to_test[name]
# 2 is for hashlib.name(...) and hashlib.new(name, ...)
self.assertGreaterEqual(len(constructors), 2)
for hash_object_constructor in constructors:
computed = hash_object_constructor(data).hexdigest()
self.assertEqual(
computed, digest,
"Hash algorithm %s constructed using %s returned hexdigest"
" %r for %d byte input data that should have hashed to %r."
% (name, hash_object_constructor,
computed, len(data), digest))
示例10: check_update
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def check_update(self, name, data, digest):
constructors = self.constructors_to_test[name]
# 2 is for hashlib.name(...) and hashlib.new(name, ...)
self.assertGreaterEqual(len(constructors), 2)
for hash_object_constructor in constructors:
h = hash_object_constructor()
h.update(data)
computed = h.hexdigest()
self.assertEqual(
computed, digest,
"Hash algorithm %s using %s when updated returned hexdigest"
" %r for %d byte input data that should have hashed to %r."
% (name, hash_object_constructor,
computed, len(data), digest))
示例11: check_unicode
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def check_unicode(self, algorithm_name):
# Unicode objects are not allowed as input.
expected = hashlib.new(algorithm_name, str(u'spam')).hexdigest()
self.check(algorithm_name, u'spam', expected)
示例12: test_bytes_hashing
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def test_bytes_hashing(self):
"""test interaction of bytes w/ hashing modules"""
import _sha, _sha256, _sha512, _md5
for hashLib in (_sha.new, _sha256.sha256, _sha512.sha512, _sha512.sha384, _md5.new):
x = hashLib(b'abc')
x.update(b'abc')
#For now just make sure this doesn't throw
temp = hashLib(bytearray(b'abc'))
x.update(bytearray(b'abc'))
示例13: test_unknown_hash
# 需要导入模块: import _md5 [as 别名]
# 或者: from _md5 import new [as 别名]
def test_unknown_hash(self):
self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam')
self.assertRaises(TypeError, hashlib.new, 1)