From 92eddb11d32c04b3e596157b39b768063b748981 Mon Sep 17 00:00:00 2001 From: jagruti8 Date: Wed, 17 Aug 2022 18:26:44 +0000 Subject: [PATCH 1/5] Fixes to the validation script --- first_validation.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/first_validation.py b/first_validation.py index cfbd543..ffc97e0 100644 --- a/first_validation.py +++ b/first_validation.py @@ -31,7 +31,9 @@ def hash_for_fname(fname): # Convert a string filename to a Path object. fpath = Path(fname) # Your code here. - return 'not-really-the-hash' + contents_fpath = fpath.read_bytes() + hash_value_fpath = sha1(contents_fpath).hexdigest() + return hash_value_fpath # Fill in the function above to make the test below pass. @@ -48,11 +50,23 @@ def check_hashes(hash_fname): # Directory containing hash filenames file. data_dir = hash_pth.parent # Read in text for hash filename + text_file = hash_pth.read_text() # Split into lines. + lines = text_file.splitlines() # For each line: + for line in lines: # Split each line into expected_hash and filename + a = line.split(' ') # Calculate actual hash for given filename. + path = data_dir / a[1] + content = path.read_bytes() + hash_value = sha1(content).hexdigest() + # Check actual hash against expected hash + if hash_value != a[0]: + break + return True + # Return False if any of the hashes do not match. return False From fa4d5257a5003facdc03b378153f9c4b7f33f4bc Mon Sep 17 00:00:00 2001 From: jagruti8 Date: Wed, 17 Aug 2022 21:36:25 +0000 Subject: [PATCH 2/5] Fixes to the validation script for the second time --- first_validation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/first_validation.py b/first_validation.py index ffc97e0..1771c59 100644 --- a/first_validation.py +++ b/first_validation.py @@ -54,6 +54,7 @@ def check_hashes(hash_fname): # Split into lines. lines = text_file.splitlines() # For each line: + i = 0 for line in lines: # Split each line into expected_hash and filename a = line.split(' ') @@ -65,7 +66,9 @@ def check_hashes(hash_fname): # Check actual hash against expected hash if hash_value != a[0]: break - return True + i += 1 + if i == 3: + return True # Return False if any of the hashes do not match. return False From 9c4fb1466ff696d2b09bd104ed7b13bc820d5085 Mon Sep 17 00:00:00 2001 From: Jagruti Patel Date: Wed, 17 Aug 2022 23:41:03 +0200 Subject: [PATCH 3/5] Update first_validation.py Co-authored-by: Matthew Brett --- first_validation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/first_validation.py b/first_validation.py index ffc97e0..afbffc3 100644 --- a/first_validation.py +++ b/first_validation.py @@ -32,8 +32,7 @@ def hash_for_fname(fname): fpath = Path(fname) # Your code here. contents_fpath = fpath.read_bytes() - hash_value_fpath = sha1(contents_fpath).hexdigest() - return hash_value_fpath + return sha1(contents_fpath).hexdigest() # Fill in the function above to make the test below pass. From 8542188ace2983e4ecc68b7a5d22f7acb470eee4 Mon Sep 17 00:00:00 2001 From: Jagruti Patel Date: Wed, 17 Aug 2022 23:41:58 +0200 Subject: [PATCH 4/5] Update first_validation.py Co-authored-by: Matthew Brett --- first_validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/first_validation.py b/first_validation.py index afbffc3..044ef93 100644 --- a/first_validation.py +++ b/first_validation.py @@ -55,7 +55,7 @@ def check_hashes(hash_fname): # For each line: for line in lines: # Split each line into expected_hash and filename - a = line.split(' ') + a = line.split() # Calculate actual hash for given filename. path = data_dir / a[1] content = path.read_bytes() From b521dd73c1b7bcf5c88cfbea5100023e7f7fe581 Mon Sep 17 00:00:00 2001 From: jagruti8 Date: Wed, 17 Aug 2022 22:15:27 +0000 Subject: [PATCH 5/5] Corrected my first_validation.py --- first_validation.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/first_validation.py b/first_validation.py index 8c48884..4549bb9 100644 --- a/first_validation.py +++ b/first_validation.py @@ -53,24 +53,18 @@ def check_hashes(hash_fname): # Split into lines. lines = text_file.splitlines() # For each line: - i = 0 for line in lines: # Split each line into expected_hash and filename - a = line.split() + hash_value, fn_name = line.split() # Calculate actual hash for given filename. - path = data_dir / a[1] - content = path.read_bytes() - hash_value = sha1(content).hexdigest() + path = data_dir / fn_name + hash_value_calc = hash_for_fname(path) # Check actual hash against expected hash - if hash_value != a[0]: - break - i += 1 - if i == 3: - return True - - # Return False if any of the hashes do not match. - return False + if hash_value != hash_value_calc: + # Return False if any of the hashes do not match. + return False + return True assert check_hashes(hashes_pth), 'Check hash list does not return True'