本文整理汇总了Python中hashlib.name方法的典型用法代码示例。如果您正苦于以下问题:Python hashlib.name方法的具体用法?Python hashlib.name怎么用?Python hashlib.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hashlib
的用法示例。
在下文中一共展示了hashlib.name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_large_update
# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import name [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: check
# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import name [as 别名]
def check(self, name, data, hexdigest):
hexdigest = hexdigest.lower()
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:
m = hash_object_constructor(data)
computed = m.hexdigest()
self.assertEqual(
computed, hexdigest,
"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), hexdigest))
computed = m.digest()
digest = bytes.fromhex(hexdigest)
self.assertEqual(computed, digest)
self.assertEqual(len(digest), m.digest_size)
示例3: test_hexdigest
# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import name [as 别名]
def test_hexdigest(self):
for name in self.supported_hash_names:
h = hashlib.new(name)
self.assertTrue(hexstr(h.digest()) == h.hexdigest())
示例4: check
# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import name [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))
示例5: check_update
# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import name [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))
示例6: test_name_attribute
# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import name [as 别名]
def test_name_attribute(self):
for cons in self.hash_constructors:
h = cons()
self.assertIsInstance(h.name, str)
self.assertIn(h.name, self.supported_hash_names)
self.assertEqual(h.name, hashlib.new(h.name).name)
示例7: check_blocksize_name
# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import name [as 别名]
def check_blocksize_name(self, name, block_size=0, digest_size=0):
constructors = self.constructors_to_test[name]
for hash_object_constructor in constructors:
m = hash_object_constructor()
self.assertEqual(m.block_size, block_size)
self.assertEqual(m.digest_size, digest_size)
self.assertEqual(len(m.digest()), digest_size)
self.assertEqual(m.name, name)
# split for sha3_512 / _sha3.sha3 object
self.assertIn(name.split("_")[0], repr(m))