@@ -188,23 +188,28 @@ async def _download(claim: StorageDriverClaim) -> Payload:
188188 f"S3StorageDriver retrieve failed [bucket={ bucket } , key={ key } ]"
189189 ) from e
190190
191- expected_hash = claim .claim_data .get ("hash_value" )
192191 hash_algorithm = claim .claim_data .get ("hash_algorithm" )
193- if expected_hash and hash_algorithm :
194- if hash_algorithm != "sha256" :
195- raise ValueError (
196- f"S3StorageDriver unsupported hash algorithm "
197- f"[bucket={ bucket } , key={ key } ]: "
198- f"expected sha256, got { hash_algorithm } "
199- )
200- actual_hash = hashlib .sha256 (payload_bytes ).hexdigest ().lower ()
201- if actual_hash != expected_hash :
202- raise ValueError (
203- f"S3StorageDriver integrity check failed "
204- f"[bucket={ bucket } , key={ key } ]: "
205- f"expected { hash_algorithm } :{ expected_hash } , "
206- f"got { hash_algorithm } :{ actual_hash } "
207- )
192+ expected_hash = claim .claim_data .get ("hash_value" )
193+ if not hash_algorithm or not expected_hash :
194+ raise ValueError (
195+ f"S3StorageDriver claim is missing required content hash information "
196+ f"[bucket={ bucket } , key={ key } ]: "
197+ f"claim_data must contain 'hash_algorithm' and 'hash_value'"
198+ )
199+ if hash_algorithm != "sha256" :
200+ raise ValueError (
201+ f"S3StorageDriver unsupported hash algorithm "
202+ f"[bucket={ bucket } , key={ key } ]: "
203+ f"expected sha256, got { hash_algorithm } "
204+ )
205+ actual_hash = hashlib .sha256 (payload_bytes ).hexdigest ().lower ()
206+ if actual_hash != expected_hash :
207+ raise ValueError (
208+ f"S3StorageDriver integrity check failed "
209+ f"[bucket={ bucket } , key={ key } ]: "
210+ f"expected { hash_algorithm } :{ expected_hash } , "
211+ f"got { hash_algorithm } :{ actual_hash } "
212+ )
208213
209214 payload = Payload ()
210215 payload .ParseFromString (payload_bytes )
0 commit comments