@@ -96,28 +96,33 @@ func WithParentLayers(parentLayers []*cimfs.BlockCIM) BlockCIMLayerImportOpt {
9696 }
9797}
9898
99- func writeIntegrityChecksumInfoFile (ctx context.Context , blockPath string ) error {
99+ func GetIntegrityChecksum (ctx context.Context , blockPath string , pathName string ) ( string , error ) {
100100 log .G (ctx ).Debugf ("writing integrity checksum file for block CIM `%s`" , blockPath )
101101 // for convenience write a file that has the hex encoded root digest of the generated verified CIM.
102102 // this same hex string can be used in the confidential policy.
103+ // also return the integrity checksum as a string for integrity-vhd tooling.
103104 digest , err := cimfs .GetVerificationInfo (blockPath )
104105 if err != nil {
105- return fmt .Errorf ("failed to query verified info of the CIM layer: %w" , err )
106+ return "" , fmt .Errorf ("failed to query verified info of the CIM layer: %w" , err )
106107 }
107108
108- digestFile , err := os .Create (filepath .Join (filepath .Dir (blockPath ), "integrity_checksum" ))
109- if err != nil {
110- return fmt .Errorf ("failed to create verification info file: %w" , err )
111- }
112- defer digestFile .Close ()
113-
114109 digestStr := hex .EncodeToString (digest )
115- if wn , err := digestFile .WriteString (digestStr ); err != nil {
116- return fmt .Errorf ("failed to write verification info: %w" , err )
117- } else if wn != len (digestStr ) {
118- return fmt .Errorf ("incomplete write of verification info: %w" , err )
110+
111+ // only create a file if a path name is provided
112+ if pathName != "" {
113+ digestFile , err := os .Create (filepath .Join (filepath .Dir (blockPath ), pathName ))
114+ if err != nil {
115+ return "" , fmt .Errorf ("failed to create verification info file: %w" , err )
116+ }
117+ defer digestFile .Close ()
118+
119+ if wn , err := digestFile .WriteString (digestStr ); err != nil {
120+ return "" , fmt .Errorf ("failed to write verification info: %w" , err )
121+ } else if wn != len (digestStr ) {
122+ return "" , fmt .Errorf ("incomplete write of verification info: %w" , err )
123+ }
119124 }
120- return nil
125+ return digestStr , nil
121126}
122127
123128func ImportBlockCIMLayerWithOpts (ctx context.Context , r io.Reader , layer * cimfs.BlockCIM , opts ... BlockCIMLayerImportOpt ) (_ int64 , err error ) {
@@ -164,7 +169,7 @@ func ImportBlockCIMLayerWithOpts(ctx context.Context, r io.Reader, layer *cimfs.
164169 }
165170
166171 if config .dataIntegrity {
167- if err = writeIntegrityChecksumInfoFile (ctx , layer .BlockPath ); err != nil {
172+ if _ , err = GetIntegrityChecksum (ctx , layer .BlockPath , "integrity_checksum" ); err != nil {
168173 return 0 , err
169174 }
170175 }
@@ -358,5 +363,10 @@ func MergeBlockCIMLayersWithOpts(ctx context.Context, sourceCIMs []*cimfs.BlockC
358363 return fmt .Errorf ("append VHD footer to block CIM: %w" , err )
359364 }
360365 }
366+ if config .dataIntegrity {
367+ if _ , err = GetIntegrityChecksum (ctx , mergedCIM .BlockPath , "merged_integrity_checksum" ); err != nil {
368+ return err
369+ }
370+ }
361371 return nil
362372}
0 commit comments