cryptography.checksums


Module Contents

Classes

Hasher

Allows checksum generation of binary data either from a file or message.

class Hasher

Allows checksum generation of binary data either from a file or message.

get_file_checksum(filename, block=2**20)

|coro|

Generates a calculated SHA512 hash for a given file.

Parameters:
  • filename (str) – The name of the file to generate the checksum for.

  • block (Optional[int]) – Chunk size to read and hash the file in bytes. Default is 2^20.

Returns:

The calculated SHA512 hash of the file, or None if there was an error generating the checksum.

Return type:

str

Notes

  • This function generates a SHA512 hash for a given file by reading the file in blocks and hashing each block. The generated hash is a digest checksum (a unique fixed-sized representation of the file content) and the file is treated as a binary file (read in rb mode) for proper handling of all types of files.

  • The reason SHA512 was chosen is purely for the lack of collisions at runtime when performing dynamic checks.