@@ -96,7 +96,7 @@ func WithParentLayers(parentLayers []*cimfs.BlockCIM) BlockCIMLayerImportOpt {
9696 }
9797}
9898
99- func writeIntegrityChecksumInfoFile (ctx context.Context , blockPath string ) error {
99+ func writeIntegrityChecksumInfoFile (ctx context.Context , blockPath string , pathName 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.
@@ -105,7 +105,7 @@ func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string) error
105105 return fmt .Errorf ("failed to query verified info of the CIM layer: %w" , err )
106106 }
107107
108- digestFile , err := os .Create (filepath .Join (filepath .Dir (blockPath ), "integrity_checksum" ))
108+ digestFile , err := os .Create (filepath .Join (filepath .Dir (blockPath ), pathName ))
109109 if err != nil {
110110 return fmt .Errorf ("failed to create verification info file: %w" , err )
111111 }
@@ -120,6 +120,18 @@ func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string) error
120120 return nil
121121}
122122
123+ func GetIntegrityChecksum (ctx context.Context , blockPath string ) (string , error ) {
124+ log .G (ctx ).Debugf ("Getting integrity checksum for block CIM `%s`" , blockPath )
125+ digest , err := cimfs .GetVerificationInfo (blockPath )
126+ if err != nil {
127+ return "" , fmt .Errorf ("failed to query verified info of the CIM layer: %w" , err )
128+ }
129+
130+ digestStr := hex .EncodeToString (digest )
131+
132+ return digestStr , nil
133+ }
134+
123135func ImportBlockCIMLayerWithOpts (ctx context.Context , r io.Reader , layer * cimfs.BlockCIM , opts ... BlockCIMLayerImportOpt ) (_ int64 , err error ) {
124136 log .G (ctx ).WithField ("layer" , layer ).Debug ("Importing block CIM layer from tar" )
125137
@@ -164,7 +176,7 @@ func ImportBlockCIMLayerWithOpts(ctx context.Context, r io.Reader, layer *cimfs.
164176 }
165177
166178 if config .dataIntegrity {
167- if err = writeIntegrityChecksumInfoFile (ctx , layer .BlockPath ); err != nil {
179+ if err = writeIntegrityChecksumInfoFile (ctx , layer .BlockPath , "integrity_checksum" ); err != nil {
168180 return 0 , err
169181 }
170182 }
@@ -358,5 +370,10 @@ func MergeBlockCIMLayersWithOpts(ctx context.Context, sourceCIMs []*cimfs.BlockC
358370 return fmt .Errorf ("append VHD footer to block CIM: %w" , err )
359371 }
360372 }
373+ if config .dataIntegrity {
374+ if err = writeIntegrityChecksumInfoFile (ctx , mergedCIM .BlockPath , "merged_integrity_checksum" ); err != nil {
375+ return err
376+ }
377+ }
361378 return nil
362379}
0 commit comments