How to use the rhash.RHash function in RHash

To help you get started, we’ve selected a few RHash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rhash / RHash / bindings / python / test_rhash.py View on Github external
def test_shift_operator(self):
        """Test the << operator"""
        ctx = rhash.RHash(rhash.MD5)
        ctx << 'a' << 'bc'
        # MD5( 'abc' )
        self.assertEqual('900150983cd24fb0d6963f7d28e17f72', str(ctx.finish()))
github rhash / RHash / bindings / python / test_rhash.py View on Github external
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)
github rhash / RHash / bindings / python / test_rhash.py View on Github external
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))