Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_update(self):
"""Test the sequential update calls"""
ctx = rhash.RHash(rhash.CRC32 | rhash.MD5)
ctx.update('Hello, ').update('world!').finish()
self.assertEqual('EBE6C6E6', ctx.HEX(rhash.CRC32))
self.assertEqual('6cd3556deb0da54bca060b4c39479839', ctx.hex(rhash.MD5))
def test_all_hashes(self):
"""Verify all hash functions"""
ctx = rhash.RHash(rhash.ALL)
ctx.update('a')
ctx.finish()
self.assertEqual('e8b7be43', ctx.hash(rhash.CRC32))
self.assertEqual('c1d04330', ctx.hash(rhash.CRC32C))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.MD4))
self.assertEqual('0cc175b9c0f1b6a831c399e269772661', ctx.hash(rhash.MD5))
self.assertEqual(
'86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', ctx.hash(rhash.SHA1))
self.assertEqual(
'77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809',
ctx.hash(rhash.TIGER))
self.assertEqual(
'czquwh3iyxbf5l3bgyugzhassmxu647ip2ike4y', ctx.hash(rhash.TTH))
self.assertEqual(40, len(ctx.hash(rhash.BTIH)))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.ED2K))
self.assertEqual('q336in72uwt7zyk5dxolt2xk5i3xmz5y', ctx.hash(rhash.AICH))
def test_shift_operator(self):
"""Test the << operator"""
ctx = rhash.RHash(rhash.MD5)
ctx << 'a' << 'bc'
# MD5( 'abc' )
self.assertEqual('900150983cd24fb0d6963f7d28e17f72', str(ctx.finish()))
def test_update_file(self):
"""Test the update_file() method"""
path = 'python_test_input_123.txt'
file = open(path, 'wb')
file.write(b"\0\1\2\n")
file.close()
ctx = rhash.RHash(rhash.SHA1)
ctx.update_file(path).finish()
self.assertEqual('e3869ec477661fad6b9fc25914bb2eee5455b483', str(ctx))
self.assertEqual(
'e3869ec477661fad6b9fc25914bb2eee5455b483',
rhash.hash_for_file(path, rhash.SHA1))
self.assertEqual(
'magnet:?xl=4&dn=python_test_input_123.txt&xt=urn:tree:tiger:c6docz63fpef5pdfpz35z7mw2iozshxlpr4erza',
rhash.magnet_for_file(path, rhash.TTH))
os.remove(path)
def test_magnet(self):
"""Test calculation of a magnet link"""
ctx = rhash.RHash(rhash.MD5 | rhash.TTH)
ctx.update('abc').finish()
self.assertEqual(
'magnet:?xl=3&dn=file.txt&xt=urn:md5:900150983cd24fb0d6963f7d28e17f72&xt=urn:tree:tiger:asd4ujseh5m47pdyb46kbtsqtsgdklbhyxomuia',
ctx.magnet('file.txt'))
def test_output_formats(self):
"""Test all output formats of a message digest"""
ctx = rhash.RHash(rhash.MD5 | rhash.TTH).finish()
self.assertEqual(
'5d9ed00a030e638bdb753a6a24fb900e5a63b8e73e6c25b6',
ctx.hex(rhash.TTH))
self.assertEqual('2qoyzwmpaczaj2mabgmoz6ccpy', ctx.base32(rhash.MD5))
self.assertEqual('1B2M2Y8AsgTpgAmY7PhCfg==', ctx.base64(rhash.MD5))
self.assertEqual(
b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e',
ctx.raw(rhash.MD5))
def test_all_hashes(self):
"""Verify all hash functions"""
ctx = rhash.RHash(rhash.ALL)
ctx.update('a')
ctx.finish()
self.assertEqual('e8b7be43', ctx.hash(rhash.CRC32))
self.assertEqual('c1d04330', ctx.hash(rhash.CRC32C))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.MD4))
self.assertEqual('0cc175b9c0f1b6a831c399e269772661', ctx.hash(rhash.MD5))
self.assertEqual(
'86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', ctx.hash(rhash.SHA1))
self.assertEqual(
'77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809',
ctx.hash(rhash.TIGER))
self.assertEqual(
'czquwh3iyxbf5l3bgyugzhassmxu647ip2ike4y', ctx.hash(rhash.TTH))
self.assertEqual(40, len(ctx.hash(rhash.BTIH)))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.ED2K))
self.assertEqual('q336in72uwt7zyk5dxolt2xk5i3xmz5y', ctx.hash(rhash.AICH))
self.assertEqual(
'8aca2602792aec6f11a67206531fb7d7f0dff59413145e6973c45001d0087b42d11bc645413aeff63a42391a39145a591a92200d560195e53b478584fdae231a',
ctx.hash(rhash.WHIRLPOOL))
def test_all_hashes(self):
"""Verify all hash functions"""
ctx = rhash.RHash(rhash.ALL)
ctx.update('a')
ctx.finish()
self.assertEqual('e8b7be43', ctx.hash(rhash.CRC32))
self.assertEqual('c1d04330', ctx.hash(rhash.CRC32C))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.MD4))
self.assertEqual('0cc175b9c0f1b6a831c399e269772661', ctx.hash(rhash.MD5))
self.assertEqual(
'86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', ctx.hash(rhash.SHA1))
self.assertEqual(
'77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809',
ctx.hash(rhash.TIGER))
self.assertEqual(
'czquwh3iyxbf5l3bgyugzhassmxu647ip2ike4y', ctx.hash(rhash.TTH))
self.assertEqual(40, len(ctx.hash(rhash.BTIH)))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.ED2K))
self.assertEqual('q336in72uwt7zyk5dxolt2xk5i3xmz5y', ctx.hash(rhash.AICH))
self.assertEqual(
'8aca2602792aec6f11a67206531fb7d7f0dff59413145e6973c45001d0087b42d11bc645413aeff63a42391a39145a591a92200d560195e53b478584fdae231a',
ctx.hash(rhash.WHIRLPOOL))
self.assertEqual(
'0bdc9d2d256b3ee9daae347be6f4dc835a467ffe', ctx.hash(rhash.RIPEMD160))
self.assertEqual(
def test_update_file(self):
"""Test the update_file() method"""
path = 'python_test_input_123.txt'
file = open(path, 'wb')
file.write(b"\0\1\2\n")
file.close()
ctx = rhash.RHash(rhash.SHA1)
ctx.update_file(path).finish()
self.assertEqual('e3869ec477661fad6b9fc25914bb2eee5455b483', str(ctx))
self.assertEqual(
'e3869ec477661fad6b9fc25914bb2eee5455b483',
rhash.hash_for_file(path, rhash.SHA1))
self.assertEqual(
'magnet:?xl=4&dn=python_test_input_123.txt&xt=urn:tree:tiger:c6docz63fpef5pdfpz35z7mw2iozshxlpr4erza',
rhash.magnet_for_file(path, rhash.TTH))
os.remove(path)
def test_all_hashes(self):
"""Verify all hash functions"""
ctx = rhash.RHash(rhash.ALL)
ctx.update('a')
ctx.finish()
self.assertEqual('e8b7be43', ctx.hash(rhash.CRC32))
self.assertEqual('c1d04330', ctx.hash(rhash.CRC32C))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.MD4))
self.assertEqual('0cc175b9c0f1b6a831c399e269772661', ctx.hash(rhash.MD5))
self.assertEqual(
'86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', ctx.hash(rhash.SHA1))
self.assertEqual(
'77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809',
ctx.hash(rhash.TIGER))
self.assertEqual(
'czquwh3iyxbf5l3bgyugzhassmxu647ip2ike4y', ctx.hash(rhash.TTH))
self.assertEqual(40, len(ctx.hash(rhash.BTIH)))
self.assertEqual('bde52cb31de33e46245e05fbdbd6fb24', ctx.hash(rhash.ED2K))
self.assertEqual('q336in72uwt7zyk5dxolt2xk5i3xmz5y', ctx.hash(rhash.AICH))
self.assertEqual(
'8aca2602792aec6f11a67206531fb7d7f0dff59413145e6973c45001d0087b42d11bc645413aeff63a42391a39145a591a92200d560195e53b478584fdae231a',
ctx.hash(rhash.WHIRLPOOL))
self.assertEqual(
'0bdc9d2d256b3ee9daae347be6f4dc835a467ffe', ctx.hash(rhash.RIPEMD160))
self.assertEqual(
'd42c539e367c66e9c88a801f6649349c21871b4344c6a573f849fdce62f314dd',
ctx.hash(rhash.GOST94))