@@ -815,6 +815,44 @@ def test_sign_file_callback_signer(self):
815815 finally :
816816 shutil .rmtree (temp_dir )
817817
818+ def test_sign_file_callback_signer_managed (self ):
819+ """Test signing a file using the sign_file method with context managers."""
820+
821+ temp_dir = tempfile .mkdtemp ()
822+
823+ try :
824+ output_path = os .path .join (temp_dir , "signed_output_managed.jpg" )
825+
826+ # Create builder and signer with context managers
827+ with Builder (self .manifestDefinition ) as builder , create_signer (
828+ callback = self .callback_signer_es256 ,
829+ alg = SigningAlg .ES256 ,
830+ certs = self .certs .decode ('utf-8' ),
831+ tsa_url = "http://timestamp.digicert.com"
832+ ) as signer :
833+
834+ # Sign the file
835+ result , manifest_bytes = builder .sign_file (
836+ source_path = self .testPath ,
837+ dest_path = output_path ,
838+ signer = signer
839+ )
840+
841+ # Verify results
842+ self .assertTrue (os .path .exists (output_path ))
843+ self .assertIsInstance (result , int )
844+ self .assertIsInstance (manifest_bytes , bytes )
845+ self .assertGreater (len (manifest_bytes ), 0 )
846+
847+ # Verify signed data can be read
848+ with open (output_path , "rb" ) as file , Reader ("image/jpeg" , file ) as reader :
849+ json_data = reader .json ()
850+ self .assertIn ("Python Test" , json_data )
851+ self .assertNotIn ("validation_status" , json_data )
852+
853+ finally :
854+ shutil .rmtree (temp_dir )
855+
818856 def test_builder_sign_file_callback_signer_from_callback (self ):
819857 """Test signing a file using the sign_file method with Signer.from_callback."""
820858
0 commit comments