@@ -278,6 +278,23 @@ def key_to_pem(priv: rsa.RSAPrivateKey | ec.EllipticCurvePrivateKey) -> bytes:
278278 )
279279
280280
281+ def _build_hashing_config_from_fdp (
282+ fdp : atheris .FuzzedDataProvider ,
283+ extra_ignores : list [Path ],
284+ signature_path : Path ,
285+ ) -> hashing .Config :
286+ alg = ["sha256" , "blake2" , "blake3" ][fdp .ConsumeIntInRange (0 , 2 )]
287+ hcfg = hashing .Config ().set_ignored_paths (
288+ paths = [* list (extra_ignores ), signature_path ],
289+ ignore_git_paths = fdp .ConsumeBool (),
290+ )
291+ if fdp .ConsumeBool ():
292+ hcfg .use_file_serialization (hashing_algorithm = alg )
293+ else :
294+ hcfg .use_shard_serialization (hashing_algorithm = alg )
295+ return hcfg
296+
297+
281298def TestOneInput (data : bytes ):
282299 fdp = atheris .FuzzedDataProvider (data )
283300
@@ -331,31 +348,23 @@ def TestOneInput(data: bytes):
331348 fname = f"signature-{ _rand_utf8 (fdp , 3 , 12 ).replace ('/' , '_' )} .sig"
332349 signature_path = model_path_p / fname
333350
334- # Ignores
335- ignore_git = fdp .ConsumeBool ()
351+ # Ignores (collected for hashing config)
336352 extra_ignores : list [Path ] = []
337353
354+ # Build hashing config (serialization + algorithm + ignores)
355+ hcfg = _build_hashing_config_from_fdp (fdp , extra_ignores , signature_path )
356+
338357 # 4) Sign and 5) Verify
339358 try :
340359 signing .Config ().use_certificate_signer (
341360 private_key = leaf_key_path ,
342361 signing_certificate = leaf_cert_path ,
343362 certificate_chain = chain_paths ,
344- ).set_hashing_config (
345- hashing .Config ().set_ignored_paths (
346- paths = [* list (extra_ignores ), signature_path ],
347- ignore_git_paths = ignore_git ,
348- )
349- ).sign (model_path_p , signature_path )
363+ ).set_hashing_config (hcfg ).sign (model_path_p , signature_path )
350364
351365 verifying .Config ().use_certificate_verifier (
352366 certificate_chain = chain_paths , log_fingerprints = False
353- ).set_hashing_config (
354- hashing .Config ().set_ignored_paths (
355- paths = [* list (extra_ignores ), signature_path ],
356- ignore_git_paths = ignore_git ,
357- )
358- ).verify (model_path_p , signature_path )
367+ ).set_hashing_config (hcfg ).verify (model_path_p , signature_path )
359368
360369 finally :
361370 # Always clean up temp dirs
0 commit comments