craft_parts.sources.checksum module

Helpers to compute and verify file checksums.

craft_parts.sources.checksum.split_checksum(source_checksum)[source]

Split the given source checksum into algorithm and hash.

Parameters:

source_checksum (str) – Source checksum in algorithm/hash format.

Return type:

Tuple

Returns:

a tuple consisting of the algorithm and the hash.

Raises:

ValueError – If the checksum is not in the expected format.

craft_parts.sources.checksum.verify_checksum(source_checksum, checkfile)[source]

Verify that checkfile corresponds to the given source checksum.

Parameters:
  • source_checksum (str) – Source checksum in algorithm/hash format.

  • checkfile (Path) – The file to calculate the sum for with the algorithm defined in source_checksum.

Return type:

Tuple

Returns:

A tuple consisting of the algorithm and the hash.

Raises:
  • ValueError – If source_checksum is not of the form algorithm/hash.

  • ChecksumMismatch – If checkfile does not match the expected hash calculated with the algorithm defined in source_checksum.