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)
评论列表
文章目录