bronx.system.hash

Interface to the Python’s hashlib module that generates hashes on files, strings, …

Classes

class bronx.system.hash.HashAdapter(algorithm)[source]

Bases: object

This class provides convenient methods to generate and check hash sums on files, File objects or strings.

Parameters:

algorithm (str) – The name of an available hash algorithm (see the algorithms() static method)

property algorithm

Hash algorithm in use within this instance.

static algorithms()[source]

List of available hash algorithms.

file2hash(input_file)[source]

Returns a hash string.

Parameters:

input_file – Path to a file or opened File-like object

file2hash_fh(input_file)[source]

Returns a File-like object that contains a hash string

Parameters:

input_file – Path to a file or opened File-like object

file2hash_file(input_file, output_file)[source]

Create a plain file that contains a hash string

Parameters:
  • input_file – Path to a file or opened File-like object

  • output_file – Path to the output file

filecheck(input_file, reference)[source]

Check if input_file checks out with the hash given in reference

Parameters:
  • input_file – Path to a file or opened File-like object

  • reference – Reference hash data (path to a file, opened File-like object or string that contains the reference hash sum)

string2hash(input_data)[source]

Return a hash string.

Parameters:

input_data – Data on which the hash is computed