コード例 #1
0
ファイル: hash.py プロジェクト: 4g/pictorg
def hashf(filename):
    d = Hashxx(seed=0) # seed is optional
    d1 = Hashxx(seed=128)
    for buf in chunks(filename, 1024):
        d.update(buf)
        d1.update(buf)
    return d.digest() , d1.digest()
コード例 #2
0
    def test_one_string(self):
        h = Hashxx()
        h.update(b'hello')
        self.assertEqual(h.digest(), 4211111929)

        h = Hashxx()
        h.update(b'goodbye')
        self.assertEqual(h.digest(), 2269043192)
コード例 #3
0
ファイル: check.py プロジェクト: jjzhang166/petervaro-cutils
 def _hash(self, filepath, block_size):
     checksum = Hash()
     with open(filepath, 'rb') as file:
         buffer = file.read(block_size)
         while buffer:
             checksum.update(buffer)
             buffer = file.read(block_size)
     return checksum.digest()
コード例 #4
0
ファイル: check.py プロジェクト: matt-hayden/cutils
 def _hash(self, filepath, block_size):
     checksum = Hash()
     with open(filepath, 'rb') as file:
         buffer = file.read(block_size)
         while buffer:
             checksum.update(buffer)
             buffer = file.read(block_size)
     return checksum.digest()
コード例 #5
0
    def test_incremental(self):
        # Make sure incrementally computed results match those
        # computed all at once
        hello_hash = self.hash_value(b'hello')
        hello_world_hash = self.hash_value(b'helloworld')

        h = Hashxx()
        h.update(b'hello')
        self.assertEqual(h.digest(), hello_hash)
        h.update(b'world')
        self.assertEqual(h.digest(), hello_world_hash)
コード例 #6
0
ファイル: simple.py プロジェクト: Rockyspade/pyhashxx
def hash_multiple_values(vals):
    '''
    Same as hash_one_value but iterates over a list and uses the
    Hashxx class so it can call update() multiple times, passing in
    additional data on each call. This could also be useful for
    streaming data, and also allows you to get the current (partial)
    digest and continue adding data.
    '''
    hasher = Hashxx(seed=0)
    for idx, val in enumerate(vals):
        hasher.update(val)
        print(" Intermediate hash up to %s = %d" % (repr(vals[:idx+1]), hasher.digest()))
    print("Hash of %s = %d" % (repr(vals), hasher.digest()))
コード例 #7
0
def hash_multiple_values(vals):
    '''
    Same as hash_one_value but iterates over a list and uses the
    Hashxx class so it can call update() multiple times, passing in
    additional data on each call. This could also be useful for
    streaming data, and also allows you to get the current (partial)
    digest and continue adding data.
    '''
    hasher = Hashxx(seed=0)
    for idx, val in enumerate(vals):
        hasher.update(val)
        print(" Intermediate hash up to %s = %d" %
              (repr(vals[:idx + 1]), hasher.digest()))
    print("Hash of %s = %d" % (repr(vals), hasher.digest()))
コード例 #8
0
    def test_seeds(self):
        h = Hashxx(seed=0)
        h.update(b'hello')
        self.assertEqual(h.digest(), 4211111929)

        h = Hashxx(seed=1)
        h.update(b'hello')
        self.assertEqual(h.digest(), 4244634537)

        h = Hashxx(seed=2)
        h.update(b'hello')
        self.assertEqual(h.digest(), 4191738725)
コード例 #9
0
    def test_simultaneous(self):
        # Ensure that interleaved updates still give same results as
        # independent
        h1 = Hashxx()
        h2 = Hashxx()

        h1.update(b'he')
        h2.update(b'goo')
        h1.update(b'll')
        h2.update(b'db')
        h1.update(b'o')
        h2.update(b'ye')

        self.assertEqual(h1.digest(), self.hash_value(b'hello'))
        self.assertEqual(h2.digest(), self.hash_value(b'goodbye'))
コード例 #10
0
 def test_empty_string(self):
     h = Hashxx()
     h.update(b'')
     self.assertEqual(h.digest(), 46947589)
コード例 #11
0
 def hash_value(self, val, seed=0):
     h = Hashxx(seed=seed)
     h.update(val)
     return h.digest()
コード例 #12
0
 def test_tuple(self):
     # Tuples shouldn't affect the hash, they should be equivalent to hashing
     # each part in a separate update
     h = Hashxx()
     h.update((b'hello',b'goodbye'))
     self.assertEqual(h.digest(), 4110974955)
コード例 #13
0
 def test_multiple_strings(self):
     h = Hashxx()
     h.update(b'hello')
     h.update(b'goodbye')
     self.assertEqual(h.digest(), 4110974955)