Skip to content

Commit

Permalink
fix: move checksum verification into a separate function
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
alvarolopez committed Sep 26, 2024
1 parent c016597 commit 5eed052
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions imgsync/distros/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ def _get_file_checksum(self, path, block_size=2**20):
buf = f.read(block_size)
return sha512

def verify_checksum(
self,
location,
name,
checksum,
):
"""Verify the image's checksum."""
# TODO(aloga): not implemented yet

def _download_one(self, url, checksum):
"""Download a file.
Expand Down Expand Up @@ -99,6 +90,17 @@ def _download_one(self, url, checksum):
location.write(block)
location.flush()

self.verify_checksum(location, url, checksum, url)

def verify_checksum(
self,
location,
name,
checksum,
url
):
"""Verify the image's checksum."""

checksum_map = {"sha512": hashlib.sha512, "sha256": hashlib.sha256}
sha = checksum_map.get(checksum[0])()
block_size = 2**20
Expand Down

0 comments on commit 5eed052

Please sign in to comment.